code inside bar-trade

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #224779 quote
    kimmen
    Participant
    New

    Hello.

    I am trying to code a trading system based on inside bar. I have created an own indicator that gives 1 when an inside bar appears within my margins. With this code it is only taking trades for the upside. If the inside-bar indicator gives 1 i want to set an stop order att the high of the mother-bar and a stoploss at the low of the mother-bar.

    Question 1

    When i probacktest, it is not taking a trade every time, only sometimes. And i dont understand why?

    Question 2

    If i want it to make pending-orders both at the uppside and downside until one will be activated, can i do it with two tradingsystems? I guess i just can put one order at once in one trading-system.

    #224781 quote
    kimmen
    Participant
    New
    //status of the indicator
    indicatoractive = CALL "kims inside bar"[80, 11, 4]
    
    
    //Pending-order, pendingorder=1 make the order active more than 1 bar, until it become zero
    
    If indicatoractive=1 and pendingorder=0 and not ONMARKET  then
    pendingorder=1
    
    pipsloose=(high[1]-low[1])*10000
    entry=high[1]
    pipsgain=(high[1]-low[1])*10000
     
    elsif pendingorder=1 and not onmarket then
    buy 16 contracts at entry stop
    SET STOP pLOSS pipsloose
    SET TARGET pPROFIT pipsgain
    
    loose=low[1]
    
    
    elsif pendingorder=1 and high[0]>=entry or pendingorder=1 and low[0] <=loose or onmarket then
    pendingorder=0
    endif
    #224795 quote
    robertogozzi
    Moderator
    Master

    You should port the indicator as well, to be able to test the code.

    In line 15, you are using a STOP order which means that the current price is LOWER than the entry price, is that always the case?

    #224906 quote
    kimmen
    Participant
    New

    as it is an inside bar trade, the daughter bar must be lower than the mother bar that sets the stop order level and then the price is always below my stop order. But you are right, a gap can appear between bars. I could enter that stop order is placed for example 1 pips above the mother bar high to cover this. Do you have any better suggestions?

    #224907 quote
    kimmen
    Participant
    New
    //Definition of motherbar and doughterbar as high and low
    Motherbarhigh = high [1]
    Motherbarlow = low [1]
    
    Doughterbarhigh = high
    Doughterbarlow = low
    
    //Difinition of the motherbar opening and closing
    Motherbaropen = open [1]
    Motherbarclose = close [1]
    
    //sizemotherbody is a limit on how big the body in the bar should be set in percentage units.
    sizemotherbody=80
    
    //max limit on how big the motherbar can be and should be set in pips
    maxmotherbar=11
    
    //min-limit is set on how small the motherbar can be and should be set in pips
    minmotherbar=4
    
    //motherbody up and down are the bodies percent of the bar in decimal form.
    motherbodyup = (motherbarclose - motherbaropen)/(motherbarhigh-motherbarlow)
    motherbodydown = (motherbaropen - motherbarclose)/ (motherbarhigh-motherbarlow)
    
    
    //if statement where validity if the body of the motherbar is large enough is determined
    if motherbodyup>sizemotherbody/100 or motherbodydown>sizemotherbody/100 then
    bodyvaild=1
    else
    bodyvaild=0
    endif
    
    //if statement where a max limit is set on how big the motherbar can be.
    if motherbarhigh-motherbarlow<maxmotherbar/10000 then
    maxbarvaild = 1
    else
    maxbarvaild=0
    endif
    
    //if statement where min-limit is set on how small the motherbar can be.
    if motherbarhigh-motherbarlow>minmotherbar/10000 then
    minbarvaild = 1
    else
    minbarvaild=0
    endif
    
    //if the motherbar is greater than the doughterbar and the body in the motherbar is greater than the limit value bodyvaild and the bar is not greater than the limit value maxbarvaild and the bar is not less than the limit value minbarvaild, becomes results=1
    
    
    If Motherbarhigh > Doughterbarhigh and Motherbarlow < Doughterbarlow and bodyvaild=1 and maxbarvaild=1 and minbarvaild=1 Then
    results = 1
    else
    results=0
    Endif
    
    //sending the results to the indicator
    return results
    
    #224908 quote
    kimmen
    Participant
    New

    i forgot to say i am trying to get it working on EUR/USD 5 min chart

    #224910 quote
    JS
    Participant
    Senior
    Hi @kimmen Try this one:  
    //status of the indicator
    IndicatorActive = CALL "kims inside bar"[80,11,4]
     
    //Pending-order, pendingorder=1 make the order active more than 1 bar, until it become zero
    If IndicatorActive=1 and not ONMARKET  then
    PendingOrder=1
    
    pipsLoose=(high[1]-low[1])*10000
    Entry=high[1]
    Loose=low[1]
    pipsGain=(high[1]-low[1])*10000
    EndIf
    
    If PendingOrder=1 and not onmarket then
    buy 16 contracts at entry stop
    SET STOP pLOSS pipsLoose
    SET TARGET pPROFIT pipsGain
    EndIf
    
    If PendingOrder=1 and High[0]>=Entry or PendingOrder=1 and Low[0]<=Loose or OnMarket then
    PendingOrder=0
    EndIf
    robertogozzi and kimmen thanked this post
    #224989 quote
    kimmen
    Participant
    New

    Thanks for the help. Now it works much better. However, I don’t understand why it sometimes skips trades. For example as in the picture I am attaching, EUR/USD 5 min chart, 2023-12-07 at 09:30 and 10:25. The indicator shows 1 but it only trades on the first opportunity and skips the second.

    The changes you made that I can see is that you removed pendingorder=0 in my first if statement where I wrote: If indicatoractive=1 and pendingorder=0 and not ONMARKET then pending order=1.  Now it works better, but this probably means that pipsLoose,Entry,Loose,pipsGain changes every bar when the indicator is active until the price passes the stop order and a deal is made. Or is  “onmarket” counted already when the stop order is placed on the market? The indicator can show 1 for several bars but I want the pipsLoose,Entry,Loose,pipsGain levels to be set only after the first time. How can i fix this issue?

    thanks again for the help

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

code inside bar-trade


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kimmen @kimmen Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/03/2023
Status: Active
Attachments: 3 files
Logo Logo
Loading...