If and While structure

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #55213 quote
    PEDRAM.JOKAR
    Participant
    Average

    Dear All

    I want to code as when 2 of my conditions met then waiting for another condition to be happened to enter short and if c1 happened exit loop. please confirm below code will do what i need. with thanks. 

    IF C2 AND C4 THEN
    WHILE C6 DO
    SELLSHORT 1 CONTRACT AT MARKET
    IF C1 THEN
    BREAK
    ENDIF
    WEND
    ENDIF

     

    #55219 quote
    robertogozzi
    Moderator
    Master

    A strategy with this code will either never enter the WHILE loop if C6 is false or never exit that loop if C6 is true, since C6 and C1 are not modified once you are within the loop.

    Roberto

    PEDRAM.JOKAR thanked this post
    #55440 quote
    PEDRAM.JOKAR
    Participant
    Average

    can you pls guide me a code that , if c1 happened wait for c2 to happen then enter market and if c3 happened cancel the first if confirmation and exit the loop?

    with thanks. 

    #55443 quote
    PEDRAM.JOKAR
    Participant
    Average

    by the way, c1 will not persist. is a crossover

    #55452 quote
    Nicolas
    Keymaster
    Master

    Please post here the complete code of the strategy, not so easy to understand what you want to be coded 🙂 

     

    #55483 quote
    PEDRAM.JOKAR
    Participant
    Average
    DEFPARAM CUMULATEORDERS=FALSE
    TREND = CALL "Pedi's Trend Detector"
    K = CALL "STOCH K"
    
    C1= TREND CROSSES OVER 0
    
    C2=K CROSSES OVER K[1]
    
    C3=TREND>0
    
    //NEED TO BE COMPLETED. WHEN C1 HAPPEN WAIT UNTIL C2 HAPPEN WHEN C3 ALSO PERSISTS TO ENTER MARKET.
    
    
    
    

    NEED TO BE COMPLETED. WHEN C1 HAPPEN WAIT UNTIL C2 HAPPEN WHEN C3 ALSO PERSISTS TO ENTER MARKET

    #55492 quote
    Nicolas
    Keymaster
    Master

    Ok Pedi’s! Let’s try with this code. 🙂 

    You need first to store the fact that C1 has crossed, and there are 2 ways to know it has, first one is a test through the last X bars:

    x = 10 //last 10 bars will be tested
    testC1 = summation[x](c1)>0 //c1 was true at least one time in the last X bars

    or you can store the variable like this (but you’ll need to reset it to 0 when another trigger, but it depends on your strategy… so I do not when you’d like to reset the C1 has crossed)

    if c1 then 
     testc1 = 1
    endif

    Now that you know your c1 condition is true, let’s check the other conditions and put an order at market:

    if testc1 and c2 and c3 then 
     buy 1 contract at market 
    endif

     

    PEDRAM.JOKAR thanked this post
    #55511 quote
    PEDRAM.JOKAR
    Participant
    Average

     Thanks for clarifying advice, Nicolas. 

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

If and While structure


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/09/2017
Status: Active
Attachments: No files
Logo Logo
Loading...