Simple code returns error message

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #121152 quote
    cyrillic
    Participant
    Junior

    Completely new to coding so started a simple test program got error msg to go to prorealcode but thats too complex. Advice welcome

    // Conditions to enter long positions
    
    DEFPARAM CumulateOrders = False
    DEFPARAM FlatBefore = 065000
    DEFPARAM FlatAfter= 203000
    
    
    
    mm=ExponentialAverage[20](close)
    if mm>mm[1]then
    BUY 100 SHARES AT MARKET
    SET STOP $LOSS10
    endif
    
    #121154 quote
    robertogozzi
    Moderator
    Master

    AT line 12 leave a blank between LOSS and 10.

    #121169 quote
    cyrillic
    Participant
    Junior

    Thank you Roberto, one more question… how do I code the stochastic %K passing through %D

    #121172 quote
    Vonasi
    Moderator
    Master

    cyrillic – I have moved your topic. You posted it in the ‘Welcome New Members’ forum and it is a strategy question so I have moved it to the ProOrder forum. Please try to post in the correct forum with any future topics.

    cyrillic thanked this post
    #121173 quote
    robertogozzi
    Moderator
    Master

    There you go:

    //   Stochastic(8,4,3)
    StocK = Stochastic[8,4](close)
    StocD = Average[3,0](StocK)
    x     = StocK CROSSES OVER  StocD  //Crossing OVER
    y     = StocK CROSSES UNDER StocD  //Crossing UNDER
    cyrillic thanked this post
    #121254 quote
    cyrillic
    Participant
    Junior

    Thank you Roberto…..

    Also… If I wanted no buy/sell action to be taken until two or more commands
    have been completed, would I use several “if” command lines and where would the command
    “and” be put ??

    #121255 quote
    GraHal
    Participant
    Master

    Is this what you mean …

    If condA AND condB AND condC Then
    Buy at Market
    Endif
    robertogozzi and cyrillic thanked this post
    #121284 quote
    cyrillic
    Participant
    Junior

    Thanks GraHal ……….. Does the command need to be in one long string ?
    Everything seems to need to be just so or it bites you.. great when you know the exact format.

    #121429 quote
    GraHal
    Participant
    Master

    Does the command need to be in one long string ?

    Yes, but you can do same / similar to below.

    The auto-syntax checker is very good if you make a mistake it will let you know when you try and run the code.

    CondA = Average[20] (Close)
    CondB = Average[50] (Close)
    CondC = CondA crosses over CondB
    
     If condC Then
    Buy at Market
    Endif
    #121497 quote
    cyrillic
    Participant
    Junior

    Thanks GraHal, I’m learning…..
    Is it possible to plot the %K of the Stochastic on its own or the MACD line on its own ??
    Such as against an SMA.

    #121498 quote
    robertogozzi
    Moderator
    Master

    [scode]
    Return Stochastic[8,4](close)
    [/scode]
    This will only return the K line.
    You can apply an MA to the indicator, but this will simply replicate the D line That you have previously removed.

    GraHal and cyrillic thanked this post
    #121838 quote
    cyrillic
    Participant
    Junior

    Thank you Roberto…
    I have just tried to backtest this simple program but the syntax error now
    underlined is the > symbol, third line up (>80) What have I done wrong ?

    DEFPARAM CumulateOrders = False
    DEFPARAM FlatBefore = 081500
    DEFPARAM FlatAfter= 160000
    
    StocK = Stochastic[15,3](close)
    StocD = Average[3,0](StocK)
    y = StocK CROSSES UNDER StocD 
    If average [50](close)>average[50](3) then
    If StocK<20 and y then
    Buy at market
    Set stop loss 15
    Endif
    Endif
    // sell condition
    If StocK = Stochastic[15,3](close)>80 then
    Sell at market
    Endif
    #121839 quote
    GraHal
    Participant
    Master

    What have I done wrong ?

    Try …

    If StocK >80 Then
    Sell at market
    Endif
    #121840 quote
    robertogozzi
    Moderator
    Master

    This could be the error, at line 8:

    average[50](3)

    what is the number 3 within parentheses? That’s the place where you put the data series on which the average is computed, CLOSE, HIGH, StocK, Rsi….. not 3!

    (when omitted, the CLOSE is assumed)

    #121844 quote
    robertogozzi
    Moderator
    Master

    Also, line 15 should be:

    If StocK >80 then
    // or
    If Stochastic[15,3](close)>80 then
    
    cyrillic thanked this post
Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.

Simple code returns error message


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
cyrillic @cyrillic Participant
Summary

This topic contains 21 replies,
has 4 voices, and was last updated by GraHal
5 years, 11 months ago.

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