How to set up

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #236161 quote
    KumoNoJuzza
    Participant
    New

    Hi guys,

    I need help.

    I want to set up the stop loss or the exit condition to the open price of the preceding bar of the tradeindex(1) as per the blue dashes the attached pic. There must be an obvious way to do it but I am stuck.
    I am testing it on the following code:

     

    // 3 Candle Pattern
     
    //Strategy
    If Close[2]>Open[2] and Close[1]>Open[1] and Close<Open[2] then
    Bear=1
    Bull=0
    ElsIf Close[2]<Open[2] and Close[1]<Open[1] and Close>Open[2] then
    Bear=0
    Bull=1
    EndIf
     
    // Stop Loss Management
    If longonmarket and tradeprice(1) - close < 0 THEN
    sell 1 contract at market
    ENDIF
    
    If shortonmarket and tradeprice(1) - close > 0 THEN
    exitshort at market
    ENDIF
     
    //Timeframe (1 mn)
    If Bull=1 and Bear[1]=1 then
    buy 1 contract at market
    //DrawArrowUP(BarIndex,Low)Coloured("Green")
    ElsIf Bear=1 and Bull[1]=1 then
    sellshort 1 contract at market
    //DrawArrowDown(BarIndex,High)Coloured("Red")
    EndIf

    Thanks for your help

    #236162 quote
    JC_Bywan
    Moderator
    Master

    Hi, no attached pic ?

    #236163 quote
    KumoNoJuzza
    Participant
    New

    Sorry !! There you go

    3-Candle-pattern-strategy.png 3-Candle-pattern-strategy.png
    #236165 quote
    JC_Bywan
    Moderator
    Master

    ok, so it’s the open of the bar when code is read, you can try to replace both line 24 and line 27 by :

    set stop price open

    if you run into issues of minimum distance, use min(open, minid)

    where minid would be your broker’s minimum distance for this asset

    KumoNoJuzza thanked this post
    #236166 quote
    KumoNoJuzza
    Participant
    New

    Thanks @JC_Bywan.

    I want to keep the same SL value for the duration of the position. I don’t want to update the SL at each new bar.

    #236170 quote
    JC_Bywan
    Moderator
    Master

    By suggesting to add set stop price open in lines 24 and 27, that’s what should happen because they are inside the same if statement as the order launching, so SL would be set only then and not updated at each new bar. You can also try to do it through a variable SL in order to graph it and visualize if behaviour matches your expectations:

    If Bull=1 and Bear[1]=1 then
    buy 1 contract at market
    SL=open
    set stop price SL
    ElsIf Bear=1 and Bull[1]=1 then
    sellshort 1 contract at market
    SL=open
    set stop price SL
    EndIf
    
    graphonprice SL
    KumoNoJuzza and Iván González thanked this post
    #236173 quote
    KumoNoJuzza
    Participant
    New

    Got it !! I ll play with it.

    Thanks

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

How to set up


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by KumoNoJuzza
1 year, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/06/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...