ending a program-what to type

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #54906 quote
    cyrillic
    Participant
    Junior

    Hi
    Ive written a program but when i try to backtest it i get a message “syntax error line 35 character 1 please complete the syntax of this line ” but there’s nothing in line 35. what should I type there ?? The last line is the stoploss value. Please advise

    #54908 quote
    robertogozzi
    Moderator
    Master

    Place your cursor after the last character of your strategy, then keep the DEL key pressed for a while, just in case there’s some garbage you can’t see!

    Another way is to copy the whole strategy, from the first character to the last one, then cancel the strategy, then again paste it in a new strategy.

    I don’t know if either works but it’s worth trying!

    Roberto

    #54917 quote
    cyrillic
    Participant
    Junior
    Thanks Roberto. I’ve done that but it still comes back with the same thing and there’s nothing on the line. The previous line was the stoploss which was accepted by the syntax indicator on the left. What is the last thing you guys write into your programs ?? As you can guess I am a complete newcomer to programming, I find it very interesting but I just don’t understand this last bit. Also what are BBCodes ?? Regards Paul
    #54927 quote
    Vonasi
    Moderator
    Master

    Usually this is because you are short of an ENDIF somewhere.

    #54934 quote
    robertogozzi
    Moderator
    Master

    You should easily spot a missing ENDIF because your last lines should be indented, if this is the case.

    #54951 quote
    cyrillic
    Participant
    Junior
    Thanks Roberto and Vonasi that’s what I have done, so now it backtests but the result is nil over a year so it looks like I’ve screwed up somewhere. Wow, this is quite a learning curve. This is my first attempt (fail) can you see what’s wrong with it please DEFPARAM CumulateOrders = False DEFPARAM FlatBefore = 065000 DEFPARAM FlatAfter= 160000 // Conditions to enter long positions sto=Stochastic[15,3](close) if sto=20 then ma=Average[50](close) a=ma>ma[10] if a then BUY 1 CONTRACTS AT MARKET ENDIF ENDIF // Conditions to exit long positions ema=ExponentialAverage[21](close) if close CROSSES UNDER ema then SELL AT MARKET ENDIF // Conditions to enter short positions if sto=80 then a=Average[50](close) if a>average[10](close) then SELLSHORT 1 CONTRACTS AT MARKET ENDIF ENDIF // Conditions to exit short positions if a>average[10](close) then if sto=20 then EXITSHORT AT MARKET ENDIF ENDIF SET STOP $LOSS10
    #54952 quote
    JC_Bywan
    Moderator
    Master

    Your “if sto=20” and “if sto=80” will almost never happen, most of the time it will cross over or under those levels without ever being exactly equal to 20 or 80, so what’s inside your if statement wouldn’t be visited.

    >> For clarity of messages on ProRealCode’s forums, please use the “<>” (insert PRT code) button in the message editor toolbar to separate the text of the code part! Thank you! <<

    #55011 quote
    cyrillic
    Participant
    Junior
    Thank you Nooywan, I have changed the symbol but it now seems to backtest but there is no result, only a flat line, and that’s over a year so I must still be doing something dire. Is there a strict protocol for constructing a procedure ? This PRT code doesnt seem to copy/paste too accurately, i will repeat in normal code if you wish.
    DEFPARAM CumulateOrders = False
    DEFPARAM FlatBefore = 065000
    DEFPARAM FlatAfter= 160000
    // Conditions to enter long positions
    sto=Stochastic[15,3](close)
    if sto<=20 then
    ma=Average[50](close)
    a=ma>ma[10]
    if a then
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    ENDIF
    
    // Conditions to exit long positions
    ema=ExponentialAverage[21](close)
    if close CROSSES UNDER ema  then
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    if sto>=80 then
    a=Average[50](close)
    if a>average[10](close) then
    SELLSHORT 1 CONTRACTS AT MARKET
    ENDIF
    ENDIF
    
    // Conditions to exit short positions
    if a>average[10](close) then
    if sto<=20 then
    EXITSHORT AT MARKET
    ENDIF
    ENDIF
    SET STOP $LOSS10
    #55017 quote
    robertogozzi
    Moderator
    Master

    I tested it on Dax and EurUsd 1,2,5,10,15,30 minutes,1,2,4 hours and it works. It is a losing strategy, but it works!

    #55171 quote
    cyrillic
    Participant
    Junior
    I have to modify it but ATT i’m having problems with the backtest. First it displayed just a flat line, but now every time I click on a share it goes through the backtest routine and has changed the graph from candlestick to line chart. It does this with every chart. How do I get it back to candlestick display and turn off this backtest routine. It must be here somewhere but I can’t find it.
    #55606 quote
    cyrillic
    Participant
    Junior
    Hi When writing code , does it have to be presented in a certain sequence, could you please check this piece of a simple program and tell me what is wrong with it ?
    DEFPARAM CumulateOrders = False
    DEFPARAM FlatBefore = 083000
    DEFPARAM FlatAfter= 200000
    // Conditions to enter long positions
    sto=Stochastic[15,3](close)
    ma=Average[50](close)
    if sto<=20 then
    a=ma>=ma[5]
    if a then
    buy 2 contracts at market
    if sto>=78 then
    sell at market
    SET STOP $LOSS15
    ma=Average[50](close)
    if sto>= 78 then
    a=ma<=ma[5]
    if a then
    buy 1 contracts at market
    if sto<=20 then
    sell at market
    SET STOP $LOSS15
    endif
    endif
    endif
    ENDIF
    ENDIF
    endif
    I ran it against todays(13th) GBPCAD using 1000 units and 2 min timeframe. Visibly I see strikes at 1138, out at 1156 1258, out at 1316, 1350 (loss), 1557 out at 1612, 1821 out at 1850 The backtest showed 1 strike which was not correct so am I writing the code in the wrong order? Please advise.
    #55607 quote
    Nobody
    Participant
    Veteran
    // Definition of code parameters
    DEFPARAM CumulateOrders = False 
    DEFPARAM FlatBefore = 083000
    DEFPARAM FlatAfter= 200000
    
    // Conditions to enter long positions
    indicator1 = Stochastic[15,3](close)
    c1 = (indicator1 <= 20)
    indicator2 = Average[50](close)
    indicator3 = Average[5](close)
    c2 = (indicator2 >= indicator3)
    
    IF c1 AND c2 THEN
    BUY 2 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator4 = Stochastic[15,3](close)
    c3 = (indicator4 >= 78)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = Stochastic[15,3](close)
    c4 = (indicator5 >= 78)
    indicator6 = Average[50](close)
    indicator7 = Average[5](close)
    c5 = (indicator6 <= indicator7)
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator8 = Stochastic[15,3](close)
    c6 = (indicator8 <= 20)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP $LOSS 15

    try this ,  i assume the second buy is a short given the parameters 

    #55610 quote
    robertogozzi
    Moderator
    Master

    You should simply use

    GRAPH sto

    and you will discover that, today, sto is never <=20 so the outer block (and inner ones as well, of course) IF…ENDIF is never true.

    #55614 quote
    Nobody
    Participant
    Veteran

    Stops too tight and if thats a mean reverting strat id have shorts and longs same position size as well   

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

ending a program-what to type


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
cyrillic @cyrillic Participant
Summary

This topic contains 13 replies,
has 5 voices, and was last updated by Nobody
8 years, 2 months ago.

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