How to code UNTIL?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #113082 quote
    sulimastersulimaster
    Participant
    Average

    Hi

    I’m trying to code UNTIL using the below example. I used IF, WHILE and BREAK but an infinite loop was detected and stopped the backtest. Help please to correct my code.

    If my long trade closes early due to a stop loss, then I don’t want the system to enter into another long trade while x is still greater than y UNTIL  y > x i.e. exit long position condition is met which should reset a back to zero.

    I have tried to code a = 1 whilst x is still greater than y when my long trade closes early due to a stop loss.

    x = AroonUp[10]
    y = AroonDown[10]
    
    a = 0
    
    IF PositionPerf(1) < 0 AND TRADEPRICE(1) < TRADEPRICE(2) THEN
    WHILE (x > y)
    a = 1
    IF (y > x) THEN
    BREAK
    ENDIF
    WEND
    ENDIF
    
    // Conditions to enter long positions
    //
    IF a = 0 AND (x > y) AND (x > 70) THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    //
    IF (y > x) THEN
    SELL AT MARKET
    ENDIF

    Thanks

    Sachin

    #113084 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    It’s an infinite loop, in between WHILE ….WEND initial conditions  never change.

    Indeed there’s no need for an iteration, another IF…ENDIF will do.

    Replace lines 7-12 with:

    If x > y then
       a = 1
    ENDIF
    Nicolas and sulimaster thanked this post
    #113144 quote
    sulimastersulimaster
    Participant
    Average

    Thanks Roberto

    However, wouldn’t the suggested code change prevent the next long trade even after y becomes greater than x if there is no other trade executed after the stop loss exit trade?

    #113147 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You’ll have to assign a different value to a when it’s time to, not always.

    Replace line 4 with:

    ONCE a = 0

    Then you’ll need to add:

    a = 0

    somewhere in the code to reenable trading when you want to, according to your conditions.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

How to code UNTIL?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
sulimaster @sulimaster Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
6 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/19/2019
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...