Change a variable/flag after a LWL streak possible?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #174934 quote
    Daniel_H
    Participant
    Senior

    Hi.

    Is there possible to change or set a variable/flag after the last three trades where LWL (loss win loss) or something similar? The problem for me is when it comes to more than the last two trades. Coding statements checking the last two trades works fine.

    Example code (not complete):

    if BARINDEX = 0 then
    	LWLtrigger = 0 // After loss win loss (LWL) this variable changes to 1
    	contractscore = 0 // When below 0 a contract is added, more losses subtract more from score and wins adds back score
    endif
    
    
    if not onmarket then
    	mystrategyprofit = strategyprofit
    	
    	// Example with LL that works, the problem is three trades in a row, etc. LWL
    	if mystrategyprofit <> mystrategyprofit[1] then
    		profithistory = mystrategyprofit
    		profithistory2 = mystrategyprofit[1]
    		profhistest = profithistory < profithistory[1] and profithistory2 < profithistory2[1]
    		// Even this worked I think: profithistory < profithistory[1] and profithistory[1] < profithistory[2]
    	endif
    	
    	// More losses would subtract more from contractscore in other if statements
    	if LWLtrigger = 0 and profhistest then
    		contractscore = contractscore - 1
    		LWLtrigger = 1
    	endif
    	
    	// How to do the same concept but with three consecutive trades WLW?
    endif
    
    
    
    
    // Buy example, of course there would be complete code to set the LWLtrigger to 0 again after a win (or more wins if there where more losses using contractscore).
    if not onmarket and LWLtrigger = 0 and otherparameters then
    	buy 1 contract at market	
    endif
    
    if not onmarket and LWLtrigger = 1 and otherparameters then
    	buy 2 contract at market
    endif

     

     

    Sincerely,
    Daniel.

    #174944 quote
    robertogozzi
    Moderator
    Master

    You can keep track of the outcome of trades with this code:

    Once Gained = 0
    Once Lost   = 0
    If StrategyProfit > StrategyProfit[1] then
       Gained = 1
       Lost   = 0
    ElsIf StrategyProfit < StrategyProfit[1] then
       Gained = 0
       Lost   = 1
    Endif
    LWL = Lost and Gained[1] and Lost[2]
    Daniel_H thanked this post
    #174952 quote
    Daniel_H
    Participant
    Senior

    Thanks for your answer robertogozzi, I will definitely try that out. I won’t be able to do that until next weekend though, but will write back then again.

    Until then, I highly appreciate your answer!
    /Daniel

    #174979 quote
    Daniel_H
    Participant
    Senior

    Hi again.

    I thought we would work normal hours this week but it’s still “summer hours”, so I got some extra time. 🙂

    I’ve tried your code but it seems to have the same problem. PRT still can only keep track of the last two trades.

    Once Gained = 0
    Once Lost   = 0
    
    If StrategyProfit > StrategyProfit[1] then
    	Gained = 1
    	Lost   = 0
    ElsIf StrategyProfit < StrategyProfit[1] then
    	Gained = 0
    	Lost   = 1
    Endif
    
    LWL = Lost and Gained[1] and Lost[2]
    LW = Gained and Lost[1]
    
    graph LWL as "LWL"
    graph LW coloured(0,0,255) as "LW"

    /Daniel

    LWL-problem.jpg LWL-problem.jpg
    #174996 quote
    robertogozzi
    Moderator
    Master

    You wanted to detectc LWL, or any other sequence of your choice, to pause a strategy.

    The problem for me is when it comes to more than the last two trades“, what does that mean? what’s the problem there?

    #175041 quote
    Daniel_H
    Participant
    Senior

    Yes I wanted to detect LWL but the code doesn’t do that (as you saw in the image I added in my previous reply). I painted in where there where LWL and the graph didn’t get triggered (otherwise it would get the true value 1 opposed to 0 in the picture in those positions). The image shows successful graph of LW I used as an example which works fine on the last two trades. But the platform (PRT) don’t seem to be able to check earlier than the last two trades when it comes to wins and losses. So to be clear, I want the graph to be triggered by LWL, then I know it works.

    Thanks again,
    Daniel.

    #175070 quote
    robertogozzi
    Moderator
    Master

    Yes, I got it. The glitch was that that wirth [1]  the code is not accessing the previous result, bu the previous candle (the same for [2]).

    This one should do:

    ONCE MyProfit1 = 0
    ONCE MyProfit2 = 0
    ONCE MyProfit3 = 0
    ONCE LWL       = 0
    
    IF LWL THEN
    MyProfit1   = 0
    ENDIF
    
    If StrategyProfit > StrategyProfit[1] then
       MyProfit1 = MyProfit2
       MyProfit2 = MyProfit3
       MyProfit3 = 1
    ElsIf StrategyProfit < StrategyProfit[1] then
       MyProfit1 = MyProfit2
       MyProfit2 = MyProfit3
       MyProfit3 = -1
    Endif
    
    LWL = (MyProfit1 = -1) AND (MyProfit2 = 1) AND (MyProfit3 = -1)
    
    IF close crosses over average[20] and Not LongOnMarket then
       buy at market
    elsif close crosses under average[20] and Not ShortOnMarket then
       sellshort at market
    endif
    set stop   ploss   100
    set target pprofit 300
    
    graph LWL coloured(255,0,0,255)
    graph MyProfit1
    graph MyProfit2
    graph MyProfit3
    Daniel_H thanked this post
    #175117 quote
    Daniel_H
    Participant
    Senior

    Ok nice, I will definitely try that out later in the week.

    Thanks so far!
    /Daniel

    #175356 quote
    Daniel_H
    Participant
    Senior

    Hi again.

    Yes it works great, thanks for your help Roberto!

    You have a nice weekend!
    /Daniel

    #175643 quote
    GraHal
    Participant
    Master

    Link to Roberto code above added as Log 299 here

    Snippet Link Library

    robertogozzi and Daniel_H thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Change a variable/flag after a LWL streak possible?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Daniel_H @hagel666 Participant
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by GraHal
4 years, 6 months ago.

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