Fixing the value of the close of the current bar across subsequent bars

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #8569 quote
    merc1203
    Participant
    Average

    I am not an experienced programmer – and indeed have difficulty in defining the problem, but this is what I

    am currently having problems with:

    I am trying to define a reference price level (RPL), and different things happen above and below this price point

    Let us assume the RPL is the close of the current bar

    This RPL is valid for all future bars UNTIL certain conditions are satisfied, at which point it shifts up or down

     

    My difficulty is that because it references “close”, whose value can change every bar going forward, how do

    I fix it at the closing price of that particular bar, and ensure that it doesn’t change in every subsequent bar to the

    closing price of the subsequent bar? I’m sure this is trivial but I’m far below trivial!

     

    I would appreciate any help whatsoever

    #8570 quote
    Nicolas
    Keymaster
    Master

    Hello merc1203,

    I don’t know what your code is all about, but this kind of conditional statement would solve your problem:

    if certainconditions=1 then 
     RPL = close
    else 
     RPL = RPL[1]
    endif

    With this, if “certain conditions” are not met, your RPL value still have the same value than the previous bar.

    #8574 quote
    merc1203
    Participant
    Average

    Very good Matthew – thanks for your help and prompness …

    #8581 quote
    merc1203
    Participant
    Average

    I have just tried to ProBacktest a simple model but I get an error message …

    Syntax error. line 46 character 1

    However, Line 46 is empty, Line 45 is …

    set target Pprofit profitEntry

    Is there a protocol for ending a piece of code?

     

    Many thanks

    #8590 quote
    Nicolas
    Keymaster
    Master

    Without the whole code is quiet difficult to know what cause your syntax error 🙂

    But it feels like you have forget an “ENDIF” somewhere maybe?

    #8626 quote
    merc1203
    Participant
    Average

    Good morning,

    The code below doesn’t seem to be doing what I want it to do

    The idea is that if the current bar closes ABOVE the lowest of the last 3 bars’ highs AND WE ARE CURRENTLY IN SELL MODE then reset RPL to equal the closing price and switch to BUY MODE.

    As soon as the current bar closes BELOW the highest of the last 3 bars’ lows AND WE ARE CURRENTLY IN BUY MODE then reset RPL to equal the closing price and switch to SELL MODE

    Don’t quite know what the code is doing but it ain’t doing that!

    Any help would be very much appreciated – many thanks in anticipation

     

    once BMode = 0
    once SMode = 0
    once Mode = 0
    
    nbH = lowest[3](high)
    nbL = highest[3](low)
    
    CondB = (close > nbH)
    CondS = (close < nbL)
    if CondB and Mode <> BMode then
    RPL = close and Mode = BMode
    if CondS and Mode <> SMode then
    RPL = close and Mode = SMode
    else
    RPL = RPL[1]
    Mode = Mode[1]
    endif
    endif
    #8629 quote
    Nicolas
    Keymaster
    Master

    You were almost right.

    With this kind of statement:

    RPL = close and Mode = BMode

    can’t return anything since you are making a conditional instruction that never match something.

    I think this code would make what you want to do here:

     

    once BMode = 0
    once SMode = 0
    once Mode = 0
    
    nbH = lowest[3](high)
    nbL = highest[3](low)
    
    CondB = (close > nbH)
    CondS = (close < nbL)
    
    if CondB and Mode <> BMode then
     RPL = close 
     Mode = BMode
    elsif CondS and Mode <> SMode then
     RPL = close
     Mode = SMode
    else
     RPL = RPL[1]
     Mode = Mode[1]
    endif
    
    #8639 quote
    merc1203
    Participant
    Average

    Could someone please put me out of my misery – the code below FAILS TO TRADE AT ALL!

    I have tried substituting each individual part to try to isolate the issue but to no avail …

    The “buy side” works fine

    Many thanks in anticipation …

     

    riskEntry = 40.0
    profitEntry = 100.0
    tick = 2
    Scale = 10.0
    NofT = 5

    once BMode = 0
    once SMode = 0
    once Mode = 0

    nbH = lowest[30](high)
    nbL = highest[30](low)

    CondB = (close > nbH)
    CondS = (close < nbL)
    if CondS and Mode <> SMode then
    RPL = close
    Mode = SMode
    elsif CondB and Mode <> BMode then
    RPL = close
    Mode = BMode
    else
    RPL = RPL[1]
    Mode = Mode[1]
    endif
    CondDD = close[1]<open[1] and close[0]<open[0] and close[1]<RPL and close[0]<RPL

    CondNofT = abs(countofposition) < NofT

    CondScale = abs(close – TradePrice(1)) > Scale
    if close<RPL and CondDD and CondNofT and CondScale THEN
    SellShort 1.25 PerPoint at close – tick stop
    endif

    set stop Ploss riskEntry
    set target Pprofit profitEntry

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

Fixing the value of the close of the current bar across subsequent bars


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
merc1203 @merc1203 Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by merc1203
9 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/01/2016
Status: Active
Attachments: No files
Logo Logo
Loading...