For Statements

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #26868 quote
    NoxxiqNoxxiq
    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
    WingWing
    Participant
    Veteran

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

    #26870 quote
    NoxxiqNoxxiq
    Participant
    New
    Good eye! But sadly, no.. It’s just an example I made up now.
    #26871 quote
    WingWing
    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
    NoxxiqNoxxiq
    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
    WingWing
    Participant
    Veteran
    Use the ‘graph’ function and check how each of your variables behave.
    #26874 quote
    NoxxiqNoxxiq
    Participant
    New
    They are displayed correctly; that’s the weird part.
    #26875 quote
    WingWing
    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 WingWing
9 years, 6 months ago.

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