Basic coding question

Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #36635 quote
    BC
    Participant
    Master

    I am stucking  on a basic coding…how to code below?

    Buy 1 contract after Bullcondition appear BullCandleStyle.

    Thanks

    Bin

    //Buy condition
    Bullcondition=low crosses over Average[20](close)
    
    //Candle style
    BC1 = Close[1] < Close[2]
    BC2 = Close > Close[1]
    BullCandleStyle=BC1 and BC2
    
    //Long Entry
    IF after Bullcondition appear BullCandleStyle then
    BUY 1 CONTRACT AT market
    Endif
    
    #36648 quote
    GraHal
    Participant
    Master

    Any good or am I misunderstanding the request or the strategy?

    IF Bullcondition AND BullCandleStyle then
    BUY 1 CONTRACT AT market
    Endif
    #36666 quote
    BC
    Participant
    Master

    Hi Grahal

    Thanks, your suggestion is buy when both condition appear at same time.

    But my idea is: When bullcondition, hold the buy until BullCandle Style appear.

    #36667 quote
    GraHal
    Participant
    Master
    IF Bullcondition Then
    BarIndex = BullIndex
    Endif
    
    If BullCandleStyle and BarIndex > BullIndex Then
    BUY 1 CONTRACT AT Market
    Endif

    Or something similar … I’ll sleep on it! 🙂

    #36674 quote
    GraHal
    Participant
    Master

    How long you want to hold the condition? Couldn’t be forever as BullCondition may not be valid, so maybe you need below?

    You can optimise variable x

    IF Bullcondition Then
    BarIndex = BullIndex
    Endif
     
    If BullCandleStyle and ((BarIndex - BullIndex) < x) Then
    BUY 1 CONTRACT AT Market
    Endif

    As your Bull Condition is  …

    Bullcondition=low crosses over Average[20](close)

    why not just use …

    Bullcondition = Low > Average[20](close)

    Then you could have …

    If BullCondition and BullCancdle Them
    Buye 1 Share at Market
    Endif
    #36706 quote
    BC
    Participant
    Master

    Thanks Grahal, actually the bull condition contain 3MA and need confirm by a candle pull back.

    I found this intersting strategy from internet and seem workable, you can take a look via below link.

    http://www.tradingstrategyguides.com/big-three-trading-strategy/

    #36708 quote
    GraHal
    Participant
    Master

    Yeah link looks good, easy to read and well laid out website … I’ll digest better with my tea tonight. 🙂 It looks a lot like the Alligator Strategy?

    I felt the simplistic explanation of the Alligator a bit naff when I first studied it, but I’m pleased to say it has stuck with me and I guess that is the reason (naff)! 🙂

    https://www.forextraders.com/forex-education/forex-indicators/alligator-indicator-explained/

    There is an Indicator on here …

    https://www.prorealcode.com/prorealtime-indicators/bill-williams-alligator/

    There is also the PRT Default … see attached.

    GraHal

    Croc2.jpg Croc2.jpg
    #36778 quote
    BC
    Participant
    Master

    Hi Grahal

    I am working on big three strategy, however I stuck on the stop loss coding.

    eg: When long, stop loss should be (MA80-tradeprice), but Prorealtime only read previous tradeprice instead of current tradeprice.

    😫😫😫

    #36779 quote
    GraHal
    Participant
    Master

    Didnt use TradePrice(1) did you?

    If you put your code on here (using <> icon) we may be able to spot the reason?

    #36783 quote
    BC
    Participant
    Master

    yes, I try blank, (1) and (0), still not work.

    I am out for some alcohol to relax, will post code later a moment later.

    #36797 quote
    BC
    Participant
    Master

    Hi GraHal

    Here u go.

    defparam preloadbars = 3000
    defparam cumulateorders =false //true  //false
    
    //Big Three MA
    FMA=Average[20](close) //green  coloured(0,255,0)
    MMA=Average[40](close)//blue  coloured(0,0,255)
    SMA=Average[80](close)//red  coloured(255,0,0)
    
    //High Low Bar Setting
    CP=10
    
    //Long Entry
    if BC and BCandle then
    //BUY min(25,PositionSizeLong) CONTRACT AT MARKET
    BUY 1 CONTRACT AT MARKET
    StopLossLong=Tradeprice-SMA[1]
    //takeProfit = takeProfitLong
    endif
    
    //Long Exit
    if LongonMarket and close crosses under SMA then
    sell at market
    endif
    
    //short entry
    if SC and SCandle then
    //SELLSHORT min(25,PositionSizeShort) CONTRACT AT MARKET
    SELLSHORT 1 CONTRACT AT MARKET
    StopLossShort=SMA[1]-Tradeprice
    //takeProfit = takeProfitShort
    endif
    
    //Short Exit
    if ShortonMarket and close crosses over SMA then
    exitshort at market
    endif
    
    // Stop Loss
    if LongonMarket then
    SET STOP LOSS StopLossLong
    endif
    
    if ShortonMarket then
    SET STOP LOSS StopLossShort
    endif
    
    graph SMA
    graph Tradeprice
    graph StopLossLong
    graph StopLossShort
    
    #36798 quote
    BC
    Participant
    Master

    miss condition

     

    
    defparam preloadbars = 3000
    defparam cumulateorders =false //true //false
    
    //Big Three MA
    FMA=Average[20](close) //green coloured(0,255,0)
    MMA=Average[40](close)//blue coloured(0,0,255)
    SMA=Average[80](close)//red coloured(255,0,0)
    
    //High Low Bar Setting
    CP=10
    
    
    //Buy Signal
    B1=low > SMA and low>MMA and low>FMA
    B2=high >= highest[CP](high)
    BC=B1 and B2
    
    //Buy Candle
    BC1 = Close[1] < Close[2]
    BC2 = Close > Close[1]
    BC3 = Close > Open
    BCandle = BC1 and BC2 and BC3
    
    //Sell Signal
    S1=high < FMA and high<MMA and high<SMA
    S2=low <= lowest[CP](low)
    SC=S1 and S2
    
    //Sell Caandle
    SC1 = Close[1] > Close[2]
    SC2 = Close < Close[1]
    SC3 = Close < Open
    SCandle = SC1 and SC2 and SC3
    
    
    //Long Entry
    if BC and BCandle then
    //BUY min(25,PositionSizeLong) CONTRACT AT MARKET
    BUY 1 CONTRACT AT MARKET
    StopLossLong=Tradeprice-SMA[1]
    //takeProfit = takeProfitLong
    endif
    
    //Long Exit
    if LongonMarket and close crosses under SMA then
    sell at market
    endif
    
    //short entry
    if SC and SCandle then
    //SELLSHORT min(25,PositionSizeShort) CONTRACT AT MARKET
    SELLSHORT 1 CONTRACT AT MARKET
    StopLossShort=SMA[1]-Tradeprice
    //takeProfit = takeProfitShort
    endif
    
    //Short Exit
    if ShortonMarket and close crosses over SMA then
    exitshort at market
    endif
    
    
    // Stop Loss
    if LongonMarket then
    SET STOP LOSS StopLossLong
    endif
    
    if ShortonMarket then
    SET STOP LOSS StopLossShort
    endif
    
    graph SMA
    graph Tradeprice
    graph StopLossLong
    graph StopLossShort
    #36801 quote
    GraHal
    Participant
    Master

    what instrument / market and timeframe you running this on?

    #36802 quote
    GraHal
    Participant
    Master

    I got it going, see attached. You check it out to see if it’s doing what you want?

    Here are the code differences …

    40  StopLossLong = Tradeprice - (TradePrice-SMA[1])
    
    53  StopLossShort= Tradeprice - (SMA[1]-Tradeprice)
    
    Bin2.jpg Bin2.jpg
    #36815 quote
    BC
    Participant
    Master

    Hi Grahal

    I found below work.

    //Long Entry
    if BC and BCandle then
    BUY 1 CONTRACT AT MARKET
    BuyPrice=Close
    StopLossLong = BuyPrice - SMA
    endif
Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.

Basic coding question


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
BC @robin_chan Participant
Summary

This topic contains 30 replies,
has 3 voices, and was last updated by BC
8 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/25/2017
Status: Active
Attachments: 8 files
Logo Logo
Loading...