Coding open on Tick

Forums ProRealTime English forum ProOrder support Coding open on Tick

Viewing 14 posts - 16 through 29 (of 29 total)
  • #242864
    JS

    When you are stopped out you can also use these:

    Once BarsToWait=3

    If StrategyProfit<>StrategyProfit[1] then

    StartBar=BarIndex

    EndIf

    If NOT LongOnMarket and OpenTime=>085500 and (BarIndex-StartBar)>BarsToWait then

    Buy….

    1 user thanked author for this post.
    #242884

    This is my current code and in order to optimize it, I need to eliminate the amount of orders the system opens during chop times. However I seem unable to code this. This means that from the time we are stopped out until the next order is placed in the system. Thank you for your help!

     

    I can’t get it to work with the suggested code.

    BarIndex-TradeIndex>1

    If LongOnMarket and (BarIndex-TradeIndex)>1 and Close > TradePrice then

     

    This is my current code!

    //Conditions to enter long or short at Europe Open
    DefParam CumulateOrders=False
    DEFPARAM FLATBEFORE = 090000
    DEFPARAM FLATAFTER = 110000

    If OpenTime=085000 then
    RangeHigh=High
    RangeLow=Low
    EndIf

    If OpenTime=>085000 and OpenTime<090000 then
    RangeHigh=max(RangeHigh,High)//Highest of Range
    RangeLow=min(RangeLow,Low)//Lowest of Range
    EndIf

    If OpenTime=>085500 then
    Buy 1 contract at RangeHigh+3*pipsize Stop
    SellShort 1 contract at RangeLow-3*pipsize Stop
    EndIf

    //Set Stop Loss
    IF LongOnMarket THEN
    SET STOP LOSS RangeLow

    ENDIF

    IF ShortOnMarket THEN
    SET STOP LOSS RangeHigh

    ENDIF

     

    GraphOnPrice RangeHigh as “RangeHigh”
    GraphOnPrice RangeLow as “RangeLow”

    #242887
    JS

    You can use the “BarsToWait” parameter to set how many “Bars” should be between two “Trades”…

    I have adjusted the “Stop Loss” to the use of the “RangeLow” and “RangeHigh” price levels

    1 user thanked author for this post.
    #242892

    Everytime I think I got the code to do what I want it, I find another mistake and I don’t know how I can eliminate it.

    On Jan 16th (below screenshot)

    090000 order executed at the right level, however it wasn’t closed at RangeLow but 20 points lower. I tried with the trailingstart = 0 but it doesn’t change the result.

    093000 a short order was executed at the same level as the first order was stopped out. The system didn’t  wait 4 bars before entering another trade again, nor did it open a trade once it touched RangeLow

    It really drives me crazy that I don’t understand where the error lies.

    Thank you again for your help. Most appreciated

    #242903
    JS

     The use of the “Stop Trailing” is incorrect. With this type of “trailing stop,” you can only specify how many points below the position price the trailing should start.
    “Set Stop Trailing 20” will start trailing 20 points below the position price.
    Lines 24 and 25 in the code are redundant when using this trailing stop.
    Furthermore, when using “STOP” orders, there is a chance that the “pending” orders are both executed within the same bar, meaning that both RangeHigh and RangeLow are hit in the same bar…

    1 user thanked author for this post.
    #242904

    Thank you very much for the explanation of the trailing stop . So there is no way I can have the stop at RangeLow and trail it from there because it is a set level.

    I would really appreciate if you could have a look at the below screenshot, where the trade was not opened at the right level at 093000. Where is the mistake there, as the trade should open at RangeLow and not 19 points lower.

     

    #242905

    Here the screenshot

    #242907
    JS

    One possible approach could be to calculate the number of points within the range (RangeHigh, RangeLow) immediately when determining the range:
    RangePoints = (RangeHigh - RangeLow)
    Then use these points for your trailing stop:
    Set Stop Trailing RangePoints
    This way, the trailing stop starts approximately at the fixed levels.

    I looked into the 09:30:00 trade but couldn’t identify what happened there either; perhaps it was still related to the incorrectly configured trailing stop…

    1 user thanked author for this post.
    #242980

    Good morning JS

    I have been having troubles with other codes where I want the system to open at a set level. Codes with time based entries work well, however I can’t get a code working if I want a specific level to be executed. I appreciate your assistance, as I am at a loss.

    Below is the backtest of your code. Unfortunately the system does not open the trade right at 9 am. It should have been a clean short.

     

    Thank you very much for your time.

    Best Regards

    Sab

    #242992
    JS

    Hi Sab,

    When I run a backtest on the latest code (Trader Sab V2), the “Short” position is executed correctly.

    Something must have been adjusted in the latest version, right?

    1 user thanked author for this post.
    #243032

    JS, I just copied your code.

     

    What I don’t understand the trade 2 and 3, because they are opened nowhere near the range low. How can I eliminate this mistake?

    Thanks  alot.

    #243035
    JS

    There are situations with “STOP orders” that don’t work well, for example, when both stop orders are triggered in the same bar, you end up with both a “Long” and a “Short” position at the same time. The backtest module cannot handle this because, according to the rules, opposing positions are not allowed to occur/exist…

    Everything after opening the position involves “Trailing,” so the standard trailing stop probably doesn’t work optimally in combination with the “Stop orders”… an alternative is a custom trailing stop… I think there will always be situations here that you (code-wise) cannot control…

    1 user thanked author for this post.
    #243080

    I will over the weekend work on it and keep you posted. Most appreciate your insights!

     

    1 user thanked author for this post.
    avatar JS
    #243082

    I proposed an addition to the code,  after the DEFPARAM statements:

    once RangeHigh = undefined
    once RangeLow = undefined

    My reasoning for this, mainly to do with the use of GRAPHONPRICE with the RangeHigh and RangeLow variables, and the auto y-axis PRICE scale.

     

    A back-test code has a default of DEFPARAM PRELOADBARS = 1000, which would be, BARINDEX 0 to 999.

    These preload-bars are not shown in the chart, so the first chart bar, in this case, would be BARINDEX = 1000.

     

    When a variable is used in the code, it is defined with a default value = 0,  from BARINDEX = 0.

    In this codes, it’s most likely going to be a later bar before the  condition is true, to set both RANGEHigh and RANGELow  to the High and Low values for the first time.

    Therefore, both Range variables will be zero from bar 0, till the true condition bar, where the values jump to the High and Low values, for the first time.

     

    GRAPHONPRICE works similarly to RETURN, in an INDICATOR code, in terms of a variable triggering the auto y-scale if its the highest and/or lowest value displayed in the chart frame.

    This means that, if the variable(s) jump from zero in the visible chart range, to the price level, the scale will adjust to include the price range from this zero value, squashing the price candles in the process.

    The additional lines, hold off defining the Range variable’s until there set to the first time high and low values, which will be in the same price range of the candles.

    This avoids the extreme zero value and this low value overriding the lowest value displayed in the chart by the candles, and having to manually re-scale in that zone

    After, the Range variables have been set for the first time, they maybe adjusted by the next bar, or set to new values on next true condition, never return to zero.

     

    If, first trigger falls in preload- bars area, this may not be  a problem, however, if re-back-testing and looking at first trigger zone it can be a hassle if the chart needs manually re-scaling.

     

    1 user thanked author for this post.
Viewing 14 posts - 16 through 29 (of 29 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login