Automatic trading not working?

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #78209 quote
    TRADESHOCK
    Participant
    Junior

    So I’ve made a beginner system, but that’s not important I’ve set it up for when stochastic goes below 75 it should sell and when above 25 it should buy. why the hell is it not doing anything?

     

    I placed some red lines where I belive it should’ve taken action but it didn’t…

     

    any suggestions welcome thanks!

    Capture-1.jpg Capture-1.jpg
    #78211 quote
    robertogozzi
    Moderator
    Master

    We need code to tell what’s going wrong.

    TRADESHOCK thanked this post
    #78292 quote
    TRADESHOCK
    Participant
    Junior

    Hi Robert, good idea. Thank you for your reply.

     

    <

    //-------------------------------------------------------------------------
    // Main code : 1 Hour 100/200 SMA STO 14,3,3
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[100](close)
    indicator2 = Average[200](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = Stochastic[14,3](close)
    c2 = (indicator3 > 25)
    
    IF c1 AND c2 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4 = Average[100](close)
    indicator5 = Average[200](close)
    c3 = (indicator4 CROSSES UNDER indicator5)
    indicator6 = Stochastic[14,3](close)
    c4 = (indicator6 < 75)
    
    IF c3 AND c4 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 150
    SET TARGET pPROFIT 300
    
    #78297 quote
    Vonasi
    Moderator
    Master

    It is difficult to tell from your image as I can’t tell which lines are which averages but your code expects the cross and the level of stochastic conditions to be met on the same bar whereas from your image it appears that you are expecting the cross to happen and then a trade to be entered when the stochastic level is crossed a few bars later. Am I right?

    TRADESHOCK thanked this post
    #78301 quote
    TRADESHOCK
    Participant
    Junior

    Yes that’s correct, thank you for your reply. Id like the stochastic to work after the cross happens on the SMA. How would you go about fixing this? I’m very much a beginner…

    #78312 quote
    Vonasi
    Moderator
    Master

    You would need to set a flag when each event happens and then only enter when both flags are true. Something like this might work but I’ve not tested it:

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // Conditions to enter long positions
    indicator1 = Average[100](close)
    indicator2 = Average[200](close)
    indicator3 = Stochastic[14,3](close)
    
    if indicator1 CROSSES OVER indicator2 then 
    cross = 1 
    endif
    
    if indicator3 crosses over 25 then
    stochlevel = 1
    over
     
    if indicator1 CROSSES UNDER indicator2 then
    cross = -1
    endif
    
    if indicator3 crosses under 75 then
    stochlevel = -1
    
    IF cross = 1 AND stochlevel = 1 THEN 
    BUY 1 PERPOINT AT MARKET 
    ENDIF
     
    IF cross = -1 and stochlevel = =1 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
     
    // Stops and targets
    SET STOP pLOSS 150
    SET TARGET pPROFIT 300
    
    TRADESHOCK thanked this post
    #78425 quote
    TRADESHOCK
    Participant
    Junior

    Thanks for your reply Vonasi.

    I’ve not come across this problem before, it says I have a syntax error on line 34 yet I don’t have a line 34? how on earth do I fix that?

    Assistance much appreciated.

    Capture.JPG2_.jpg Capture.JPG2_.jpg Capture.JPG222.jpg Capture.JPG222.jpg
    #78428 quote
    robertogozzi
    Moderator
    Master

    Line 12 and line 20 are both missing a matching ENDIF, so at the end of the code an error message is output.

    TRADESHOCK thanked this post
    #78433 quote
    verygrubby
    Participant
    Master

    ..also line 27 has an extra = instead of a – sign..

    More haste, less speed, Vonasi!

    TRADESHOCK thanked this post
    #78461 quote
    Vonasi
    Moderator
    Master

    More haste, less speed, Vonasi!

    Looking at the time that I posted it is probably more haste, less beer!

    I think we should all leave a line or two out of our code when providing it for others and see if they can work it out on their own. Nothing in life should come too easy!

    TRADESHOCK thanked this post
    #78482 quote
    TRADESHOCK
    Participant
    Junior

    Of course the endifs where missing! I managed to correct line 27 myself but am still learning. Thanks for your help!

    #78488 quote
    Vonasi
    Moderator
    Master
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
     
    // Conditions to enter long positions
    indicator1 = Average[100](close)
    indicator2 = Average[200](close)
    indicator3 = Stochastic[14,3](close)
     
    if indicator1 CROSSES OVER indicator2 then 
    cross = 1 
    endif
     
    if indicator3 crosses over 25 then
    stochlevel = 1
    endif
     
    if indicator1 CROSSES UNDER indicator2 then
    cross = -1
    endif
     
    if indicator3 crosses under 75 then
    stochlevel = -1
    endif
     
    IF cross = 1 AND stochlevel = 1 THEN 
    BUY 1 PERPOINT AT MARKET 
    ENDIF
     
    IF cross = -1 and stochlevel = -1 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
     
    // Stops and targets
    SET STOP pLOSS 150
    SET TARGET pPROFIT 300

    Just to redeem myself the above is the corrected code – I still have no idea if it works or is what you want but at least this one was done after only one beer! 🙂

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

Automatic trading not working?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
TRADESHOCK @russellite Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by Vonasi
7 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/14/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...