Problem " OffSET "

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #80401 quote
    JR1976
    Participant
    Veteran

    I received the erro in attached during my ALgo .

    Ithink could be the trailing code ,

    SL = stoploss // Initial SL
    TP = TP
    TSL = 1 // Use TSL?
    TrailingDistance = 5 // Distance from close to TSL
    TrailingStep = 5 // Pips locked at start of TSL
    
    //************************************************************************
    IF TSL = 1 THEN
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL = 0
    CAND = 0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL = 0 AND CLOSE - TRADEPRICE(1) >= TrailingDistance*PipSize THEN
    newSL = TRADEPRICE(1) + TrailingStep*PipSize
    ENDIF
    //next moves
    CAND = BarIndex - TradeIndex
    IF newSL > 0 AND CLOSE[1] >= HIGHEST[CAND](CLOSE) THEN
    newSL = CLOSE[1] - TrailingDistance*PipSize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL > 0 THEN
    SELL AT newSL STOP
    ENDIF
    SET STOP pLOSS SL
    ENDIF
    

     

    Could you please help to understand better  ?

    Thanks

    OFFset.png OFFset.png
    #80408 quote
    robertogozzi
    Moderator
    Master

    Without the complete code is impossible to replicate it.

    You should, besides posting code, tell us what instrument, TF and backtest range it is.

    #80427 quote
    Nicolas
    Keymaster
    Master

    This problem is obvious, you cannot use an instruction with a period of 0, it is the case in your code at line 24, with the Highest instruction.

    #80447 quote
    robertogozzi
    Moderator
    Master

    Replace line 23 with

    CAND = max(1,BarIndex - TradeIndex)

    to make sure CAND is not 0.

    JR1976 thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Problem " OffSET "


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
JR1976 @jr1976 Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by robertogozzi
7 years, 6 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 09/13/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...