Hard stop using a candle

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #22654 quote
    Dymjohn
    Participant
    Senior

    Hi

    The attached code works fine except for the “stop” which closes losing trades at the end of the day using  the Flatafter condition. My intention is to place the stop 1.1 points above the high of the 8:00 am (GMT) candle. Can anyone suggest how this could be gone please? The “SellPrice” sets itself per the low of the 8:00 am candle -1.1 points correctly.

    I can graph c1 which is showing the correct value but cannot seem to work out how to link the value to the “stop”.

    Can anyone help please?

    DEFPARAM FlatAfter = 163000
    
    StartingTime = 080500
    SellPrice = Low[0] - 1.1*pointsize
    
    //sell contract
    if time >= 080500 and time < 081000 then
    sellshort 1 contract at SellPrice stop
    endif
    //stop loss
    if time = StartingTime then
    c1 = (High[0]+1.1*pointsize)
    endif
    SET STOP LOSS c1
    
    //set limit
    if time = StartingTime then
    c2 = (High[0]-Low[0])*1.5
    endif
    SET TARGET PPROFIT c2
    
    5min-break-sell.itf
    #22693 quote
    Big Hug
    Participant
    Average

     

    I’ve tried but I can’t get it to reference that first bar either :-/

    I was using this  link below.

    Hopefully Nicholas can give you some idea

    https://www.prorealcode.com/documentation/category/constants/page/2/
    
    
    #22715 quote
    Dymjohn
    Participant
    Senior

    Hi Big Hug,

    Thanks for the info. about range commands and I agree its not the solution to the problem of linking the stop to a candle.

    Nikolas may be able to help if he picks up on the problem ,if not, it seems a major restriction in the software.

    I’m sure you can use “intradayindex” to identify a particular candle although the write up if not particularly clear as the index number will be continually moving so doesn’t help.

    #22716 quote
    Big Hug
    Participant
    Average

    I’ll have another look over the w/e possibly.

    I’m sure it can be done.

    I need a clear head !

    #22717 quote
    Dymjohn
    Participant
    Senior

    Thanks for the help. I thought looking at the problem am might help but obviously not.

    #22746 quote
    JC_Bywan
    Moderator
    Master

    That’s because when using the “stop loss” command, you need to give your code your desired stop “distance” = the number of points between c1 and your entry, not c1 itself which is the stop “level”.

    So with “stop loss c1”  (c1 = high[0]+1.1*pointsize level), you have pushed your stop far away at “entry + c1” level (so roughly twice current price level), that’s why it’s never touched within the day, hence the defparam flatafter bringing an end to it.

    Changing your line “stop loss c1” into “stop loss (c1 – tradeprice)” should result in triggering the stop at the c1 level.

    #22765 quote
    Dymjohn
    Participant
    Senior

    Thank you Noobywan for your assistance easy when you know how.

    #22766 quote
    Big Hug
    Participant
    Average

    Great Noobywan – thank you . Now I have to understand it 🙂

    DEFPARAM FlatAfter = 163000
    
    StartingTime = 080500
    SellPrice = Low[0] - 1.1*pointsize
    
    //sell contract
    if time >= 080500 and time < 081000 then
    sellshort 1 contract at SellPrice stop
    endif
    //stop loss
    if time = StartingTime then
    c1 = (C1-tradeprice)
    endif
    SET STOP LOSS c1
    
    //set limit
    if time = StartingTime then
    c2 = (High[0]-Low[0])*1.5
    endif
    SET TARGET PPROFIT c2
    
    #22784 quote
    JC_Bywan
    Moderator
    Master

    I don’t agree with your line 12 “c1=C1-tradeprice”, there are two ways to do it:

    • either you can keep :
      c1 = high[0]+1.1*pointsize

      and then the syntax for the stop would be :

      set stop loss (c1 - tradeprice)
    • or you can say :
      c1 = high[0]+1.1*pointsize - tradeprice

      and then you can keep :

      set stop loss c1

      because you have made of c1 a distance rather than a level

    Should also work with “ploss” by the way… (p for points, just like first p of pprofit)

    Big Hug thanked this post
    #22830 quote
    Dymjohn
    Participant
    Senior

    Hi

    I’ve substituted your second formula on my original EA and graphed C1 and the value is not what I would expect

    reference information using the DAX for 25th January:-

    8:00 High 11691.3 Low 11676.5 candle length 14.8.

    Trade was actioned on the 8:05 candle (correctly) at 11675.4.

    The stop should have been = 11691.3+1.1-11675.4 =17.0 but when I graphed the stop it came out as 179.4.

    On test this again closed out at 163000.

    DEFPARAM FlatAfter = 163000
    
    
    StartingTime = 080500
    SellPrice = Low[0] - 1.1*pointsize
    
    //sell contract
    if time >= 080500 and time < 081000 then
    sellshort 1 contract at SellPrice stop
    endif
    //stop loss
    if time = StartingTime then
    c1 = ((High[0]+1.1*pointsize)-tradeprice)
    endif
    SET STOP LOSS c1
    
    //set limit
    if time = StartingTime then
    c2 = (High[0]-Low[0])*1.5
    endif
    SET TARGET PPROFIT c2
    graph c1
    graph tradeprice
    

    I thought it might be because we need to reset C1 at the start of day but don’t think its that.

    #22835 quote
    JC_Bywan
    Moderator
    Master

    Do you have screen capture? If I look at the IG cfd data I don’t have these values for these times, so I can’t reproduce your backtest. I assume either you’re looking at something else than my ig dax cfd (futures?) or maybe not the 25/01? Also important, what timeframe? 5 minutes? 1 minute? or (x) minutes? Specifying timeframe might be important here because if using the “easy way” tradeprice to recover your entry, this calls the price level of the latest trade, that latest trade could be either the last trade exit if not entered a new trade yet, or the latest entry, and depending on your timeframe the code might have been setting the stop with the price level of the previous exit instead of current entry (it all depends on in what order events happen and lines are read). For example first sugestion to keep c1 like you first did but make “set stop loss c1-tradeprice” would more likely take into account the latest entry rather than last sell, whilst using the other suggestion of taking tradeprice into account when defining c1 inside that if statement with time restriction could be fine for capturing the high, but not for the tradeprice depending on what timeframe is used.

    #22840 quote
    Eric
    Participant
    Master

    maybe not the best solution (and fastest) but when i do something like this i try to make an indicator first and then use it in the code by call

    indicatorlow = ? -1.1

     

    botten = CALL indicatorlow

    and the stoploss

    Sell at botten stop

     

    but if you can write it without using call its probably better

    #22842 quote
    Dymjohn
    Participant
    Senior

    Hi

    I used the IG spreadbet account and the values and timeframe are correct. The reason I took option 2 of your suggestions was because I was going to add “buys” with an “if” statement to identify whether the trade is a “buy” or “Sell” that way I can use one EA instead of two i.e. with 2 definitions of C1.

    In fact, tradeprice may be problem with buy and sell in the same EA so may need to keep them separate.

    I’ll go and have a further think but thanks for your interest and input.

    #22843 quote
    Dymjohn
    Participant
    Senior

    Thanks for the input Eric. Because I’m trying to identify the low/high  of a specific  5 minute candle at 8:00 a.m. UK time not sure how to pinpoint in an indicator the price at 8:00. I can get the code to work if I allow the low/high value to change with each candle.

    #22844 quote
    Dymjohn
    Participant
    Senior

    Hi all

    Cracked it just set c1 = Range[0]+2.2

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Hard stop using a candle


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Dymjohn @dymjohn Participant
Summary

This topic contains 15 replies,
has 4 voices, and was last updated by Eric
9 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/26/2017
Status: Active
Attachments: No files
Logo Logo
Loading...