How to reset variables

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #145947 quote
    Monochrome
    Participant
    Senior

    Im still stuck on this.

    once trigger = 0 
    if trigger = 0 and  high < bolldown then
    trigger = 1
    triggersignal = barindex
    endif
    if (barindex-triggersignal) >8 then
    trigger = 0
    endif
    if trigger = 1 and close > bollup then
    trigger = 2
    endif
    
    IF Trigger = 2  and c1 and close>c2  AND Not OnMarket and not daysForbiddenEntry THEN
    BUY 1 Contract AT Market
    SET TARGET pPROFIT 10
    SET STOP   ploss 10
    Trigger = 0
    ENDIF
    

    From what i understand the trigger =  1 is not reset and keeps adding. How do i reset all variables after trade.

    #145951 quote
    Nicolas
    Keymaster
    Master

    Your variable “trigger” is reset to 0 as soon as you enter an order at line 17.

    At next bar, the code is read and if the condition are fulfilled at line 2, the variable is set to 1.

    #145954 quote
    Monochrome
    Participant
    Senior

    How do i reset variable 1 if the conditions for variable 2 arent met?

    I tried to reset it  8 bars after variable 1, seems to not work.

    #145967 quote
    Nicolas
    Keymaster
    Master

    Sorry what are variables 1 and 2 please?

    #145970 quote
    Monochrome
    Participant
    Senior

    When the high is < bolldown this is variable 1. I named it trigger = 1.

    When trigger = 1 is active and within 8 bars if price closed above bollup i named it trigger =2 ( variable 2).

    If it dosent close above bollup within 8 bars i tried to reset it back to trigger =0.

    Im sorry i know my explanation is a little confusing.

    Defparam cumulateorders = false
    DEFPARAM FLATBEFORE = 090000
    DEFPARAM FLATAFTER = 160000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    //INDICATORS
    c1 = AverageTrueRange[14](close) > 2
    c2 = ExponentialAverage[200](close)
    Bollup = CALL "Example2 : Bollinger(1)upup"[0.66, 10]
    Bolldown = CALL "Example2 : Bollinger(1)down"[0.66, 10]
    
    //SIGNALS 
    once trigger = 0 
    ONCE trigger = 1
    if trigger = 0 and  high < bolldown  then
    trigger = 1
    triggersignal = barindex
    endif
    if (barindex-triggersignal) >8 then
    trigger = 0
    endif
    if trigger = 1 and close > bollup then
    trigger = 2
    endif
    
    //BUY CONDITIONS
    IF Trigger = 2  and c1 and close>c2 and bolldown > c2 AND Not OnMarket and not daysForbiddenEntry THEN
    BUY 1 Contract AT market 
    SET TARGET pPROFIT 10
    SET STOP   ploss 10
    Trigger = 0
    ENDIF

    This is the full code.

    #145972 quote
    Nicolas
    Keymaster
    Master

    If you GRAPH trigger, you will see at what moment the variable is set to what value, did you try? This is the first step to understand why a code is not functioning at it should, GRAPH the variables! 😉

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

How to reset variables


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Monochrome @monochrome Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Nicolas
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/30/2020
Status: Active
Attachments: No files
Logo Logo
Loading...