Variable inside IF-function gets set when condition not fulfilled

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #25731 quote
    Wilko
    Participant
    Senior

    Hello all,

    I appreciate any help with the following. Disregarding the logic of the buying (which is here only for illustrative purposes), I have in the below code three different IF-clauses. The effect I want to achieve is that when one the clauses is fulfilled and a position is entered, it won’t be filled a second time, at least not before it has been sold. But this method doesn’t seem work in PRT. If I run this on any asset intraday, the code doesn’t take any positions at all. If I GRAPH the varible values, I see that SL1, SL2 and SL3 are set to 1 throughout the backtest-period from the first bar. It beats me what’s going on. Any ideas?

    ONCE SL1 = 0
    
    ONCE SL2 = 0
    
    ONCE SL3 = 0
    
    MaxPos = 3
    
    IF CountOfLongShares<MaxPos AND close>close[1] + 10 AND SL1 = 0 THEN
    
    BUY 1 CONTRACT AT MARKET
    
    SL1 = 1
    
    ENDIF
    
    IF CountOfLongShares<MaxPos AND close>close[1]+20 AND SL2 = 0 THEN
    
    BUY 1 CONTRACT AT MARKET
    
    SL2 = 1
    
    ENDIF
    
    IF CountOfLongShares<MaxPos AND close>close[1]+30 AND SL3 = 0 THEN
    
    BUY 1 CONTRACT AT MARKET
    
    SL3 = 1
    
    ENDIF
    
    IF LongOnMarket AND BarIndex = TradeIndex + 5 THEN
    
    SELL AT MARKET
    
    SL1 = 0
    
    SL2 = 0
    
    SL3 = 0
    
    ENDIF
    #26132 quote
    Nicolas
    Keymaster
    Master

    Try to defparam preloabars to zero to see if it fix the issue.

    #26165 quote
    robertogozzi
    Moderator
    Master

    The line

    close>close[1] + 10

    probably won’t behave as you want, since you are adding 10 to much lower values which results in a huge number, Say you are buying EurUsd and the CLOSE price il 1.0523, adding 10 to it produces 11.0523, which will NEVER be true!
    Try using PIPSIZE to sort it out, as follows:

    close > (close[1] + (10 * pipsize))
    Nicolas and Wilko thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Variable inside IF-function gets set when condition not fulfilled


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Wilko @wilko Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by robertogozzi
9 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/20/2017
Status: Active
Attachments: No files
Logo Logo
Loading...