My new strategy enters at market incorrectlly

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #156260 quote
    IcaroFM
    Participant
    Veteran

    Hi, I’ve a problem with a strategy. It’s a simple strategy that buy when the value of the indicator leaves -100 and sell when the value of the indicator leaves 100.

    But I don’t know why strategy has wrong signals. I’ve tried with other markets, but I’ve the same problem. It’s probably an oversight of mine but I can’t find it. Thank you to those who want to help me.

    TD-REI.itf BacktTestGenerico.itf Mistake.png Mistake.png
    #156275 quote
    robertogozzi
    Moderator
    Master

    Give your topic a meaningful title.Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.

    Thank you 🙂

    If your code is not hundreds of lines, post it please.

    #156311 quote
    IcaroFM
    Participant
    Veteran

    Sorry for my title Roberto.

    Here the indicator:

    
    HighMom = DHigh(0) - DHigh(2)
    LowMom = DLow(0) - DLow(2 )
    
    Cond1 = (DHigh(0) >= Dlow(5) OR DHigh(0) >= DLow(6) )
    Cond2 = ( DHigh(2) >= DClose(7) OR DHigh(2) >= DClose (8) )
    Cond3 = ( DLow(0) <= DHigh (5) OR DLow(0) <= DHigh(6) )
    Cond4 = (DLow(2) <= DClose(7) OR DLow(2) <= DClose(8) )
    Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 )
    IF Cond  then
    Num = HighMom + LowMom
    Else
    Num = 0
    ENDIF
    Den = ABS( HighMom ) + ABS( LowMom )
    
    TDREI = 100 * Summation [5](Num)  / Summation [5] (Den)
    
    SignBuy=0
    SignSell=0
    if TDREI[1]=100 and TDREI<100 then
    SignSell=1
    endif
    if TDREI[1]=-100 and TDREI>-100 then
    SignBuy=1
    endif
    
    return TDREI,SignSell as "Sell",SignBuy as "Buy"

    And here the strategy

    shorta = 0
    compra = 0
    copri = 0
    vendi = 0
    
    signal,SignSell,SignBuy=Call "TD REI"
    
    //if signal[1]>99 and signal<99 then
    if SignSell=1 then
    Shorta=1
    Vendi=1
    endif
    
    //if signal[1]<-99 and signal>-99 then
    if SignBuy=1 then 
    Compra=1
    copri = 1
    endif
    
    REM - * - * -* - Comincio le azioni - * - * - * -
    
    NumContrattiMax=2
    
    IF LongOnMarket and (vendi or shorta)  THEN
    SELL AT MARKET
    ENDIF
    
    IF ShortOnMarket and (copri or compra) THEN
    EXITSHORT AT MARKET
    ENDIF
    
    IF shorta and COUNTOFSHORTSHARES<NumContrattiMax THEN
    SELLSHORT 1 contracts at market
    SET STOP %LOSS SLLong*0.1
    SET TARGET %PROFIT TPLong*0.1
    ENDIF
    
    IF compra and COUNTOFLONGSHARES<NumContrattiMax THEN
    buy 1 contracts at market
    SET STOP %LOSS SLLong*0.1
    SET TARGET %PROFIT TPLong*0.1
    ENDIF
    

    Thanks

    #156368 quote
    robertogozzi
    Moderator
    Master

    Firstly, your indicator returns 1 for both sell and buy signal making them difficult to see on the chart, I suggest that you replace lines 21 and 24 of your indicator with:

    SignSell = -50  //line21
    SignBuy  = 50   //line 24

    you don’t have to change the code in your strategy because they are TRUE being <> 0, but can easily be spotted on the chart.

    Secondly, you have added a variable named NumContrattiMax, but it can only be 1 unless you set line 1 to TRUE.

    Thirdly, you have added two variables, TPLong and SLLong as if you wanted to make those values for Long trades different from the Short ones, but you are using the same variables for both Long and Short trades.

    The trade you are talking about seems to have been opened on Dec. 7th at 01:00 (you did not specify any daye & time, which you should always do, instead) accorduing to the SHORT signal from the prior candle as you can see from my pic (-50).

    Everything seems fine to me.

    x.jpg x.jpg
    #156379 quote
    IcaroFM
    Participant
    Veteran

    Thank you Roberto.

    1. I’ve changed to -50 and 50 so I can see better on the chart.
    2. Yes, that’s right, this is a generic strategy that I use to test my ideas. So it’s not all fine. I need to see how the indicator works. But you’re right, it’s useless if the first line is set to “False” value.
    3. Yes, that’s right, as point 2, I’ve use this code to see how the indicator works.

    The different between me and you is the TD value. In that trade I’ve the indicator at 100 not less than 100. You can also see that I’ve not -5 sell signals on the bottom of the chart. I’ve dont’t understand why.

    Mistake2.png Mistake2.png
    #156387 quote
    IcaroFM
    Participant
    Veteran

    Same problem on 1 hour DAX chart.

    3 strange position that I’ve circled

    Dax1HOurStrangePositions.png Dax1HOurStrangePositions.png
    #156417 quote
    robertogozzi
    Moderator
    Master

    Prova ad usare  questa versione  dell’indicatore:

    Try using this version:

    HighMom = DHigh(0) - DHigh(2)
    LowMom = DLow(0) - DLow(2 )
    
    Cond1 = (DHigh(0) >= Dlow(5) OR DHigh(0) >= DLow(6) )
    Cond2 = ( DHigh(2) >= DClose(7) OR DHigh(2) >= DClose (8) )
    Cond3 = ( DLow(0) <= DHigh (5) OR DLow(0) <= DHigh(6) )
    Cond4 = (DLow(2) <= DClose(7) OR DLow(2) <= DClose(8) )
    Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 )
    IF Cond  then
    Num = HighMom + LowMom
    Else
    Num = 0
    ENDIF
    Den = ABS( HighMom ) + ABS( LowMom )
    
    TDREI = 100 * Summation [5](Num)  / Summation [5] (Den)
    
    SignBuy=0
    SignSell=0
    if TDREI[1]=100 and TDREI<100 then
    SignSell=-50
    endif
    if TDREI[1]=-100 and TDREI>-100 then
    SignBuy=50
    endif
    
    return TDREI AS "Td Rei",SignSell as "Sell",SignBuy as "Buy"
    #156419 quote
    IcaroFM
    Participant
    Veteran

    Same result Roberto.

    It’s not so important, this indicator doesn’t do what I’m expected, and I think that I don’t use in the future. Anyway it’s very strange, I’ve write many strategies in the past and this is the first time that happen this strange behavior

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

My new strategy enters at market incorrectlly


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
IcaroFM @icarofm Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by IcaroFM
5 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/04/2021
Status: Active
Attachments: 7 files
Logo Logo
Loading...