For Statements

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #26868 quote
    Noxxiq
    Participant
    New

    Can you use for statements for automated trading, where each indicator refers to the last bars value?

    Just a random example:

    once x=0
    ax = x/3*abs(x-5)
    
    x=x+1
    
    if barindex>100 then
    a=0
    b=0
    c=0
    
    for i=1 to 100
    a=a+ax[barindex-i+1]
    b=b+ax[barindex-i+1]*i
    c=c+ax[barindex-i+1]*i*i
    next
    endif
    
    indictor = a*b/c
    
    if close crosses under indicator
    buy n contracts at market
    endif

    Doesn’t seem to work for me.. Is it allowed?

    #26869 quote
    Wing
    Participant
    Veteran

    Could it be that you spell ‘indicator’ differently on row 18 and 20?

    #26870 quote
    Noxxiq
    Participant
    New
    Good eye! But sadly, no.. It’s just an example I made up now.
    #26871 quote
    Wing
    Participant
    Veteran
    What is the error message you receive, if any? Is there a value returned for a, b and c? Does it work with say, 30 iterations instead of 100? Could it be the close cross under indicator check that does not work?
    #26872 quote
    Noxxiq
    Participant
    New
    Literally nothing happens, I get the summary (but no trades). And I tried all kinds of conditions apart from ‘cross under’.
    #26873 quote
    Wing
    Participant
    Veteran
    Use the ‘graph’ function and check how each of your variables behave.
    #26874 quote
    Noxxiq
    Participant
    New
    They are displayed correctly; that’s the weird part.
    #26875 quote
    Wing
    Participant
    Veteran
    Do you define all your variables from the start, and have you tried for example defparam preloadbars=1000? Also, isn’t the value of ‘indicator’ much greater than the close price? I don’t think there is anything wrong with your method or the for statements here, but rather the example you have. Here is for example an indicator I have made that uses for statements to gather data from previous bars: https://www.prorealcode.com/topic/pattern-matching-price-movements-in-prt/
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

For Statements


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Noxxiq @noxxiq Participant
Summary

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

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