Function Call to user-indicator returning no data

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #83751 quote
    TimH
    Participant
    New

    Hi, I’ve written my first Indicator and am trying to call it from my trading System. The problem I have is that when I call the function from a Trading System, no data is returned.

    The indicator returns a single value (in a parameter called Result) of either 1, 2 or 99 and seems to work fine when added to a chart.

    The Trading System output shows a value of 0 which suggests something is wrong somewhere but I can’t seem to work it out.

    Any help would be gratefully received 🙂

    I’ve attached

    a) the indicator code

    b) my simple trading system which calls the indicator

    c) a screen shot which shows the indicator on the chart. This shows that there are values in the Result parameter which the indicator returns. It also shows the Trading System variables which should show the Result value however it remains at a value of 0.

    DEFPARAM cumulateorders=true
    myResult=CALL myClearBar
    Graph myResult
    
    if myResult=1  Then
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    If myResult=2 THEN
        SELL AT MARKET
    ENDIF
    DEFPARAM CALCULATEONLASTBARS = 200
    DEFPARAM DRAWONLASTBARONLY = false
    x=200 // number of bars to look back through...
    LH=99999999
    HL=0
    
    LHFound=0 // flag to indicate whether the Lowest High has been found; and the routine should now look for the Highest Low
    HLFound=0 // opposite of above...
    
    // keep looping through the specified number of bars so we know which is the nearest LH or HL
    while x>1 do
    //--------------------------------------------------------------------------------------
    // Reset flags
    result=99
    //thisBarIndex=0
    
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // look for the most recent Lowest High bar LH)
    while high[x] < LH and x>0 DO // look for a new lowest high; skip when x=0
    LH=high[x] // set the latest LH
    x=x-1 // decrement the loop
    LHFound=1 // indicate that aLH has been found
    HLFound=0 // ...and that the HL has not....
    wend
    
    //--------------------------------------------------------------------------------------
    //  Output LH bar
    if LHFound then
    //Draw where the LH was found...
    x=x+1
    //ThisBarIndex=Barindex
    DRAWTEXT("LH*", barindex-x, high[x])
    x=x-1
    //LatestLH=LH
    //LatestHL=0
    Endif
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // look for the most recent Highest Low bar (HL)
    WHILE low[x] >HL and x>0 DO// look for a new highest low; skip when x=0
    HL=low[x]// set the latest HL
    x=x-1 // decrement the loop
    HLFound=1 // indicate that a HL has been found
    LHFound=0 // ...and that the LH has not....
    WEND
    
    //--------------------------------------------------------------------------------------
    //  Output HL bar
    if HLFound then
    // Draw where the HL was found...
    x=x+1
    //LatestHL=HL
    //LatestLH=0
    //ThisBarIndex=Barindex
    DRAWTEXT("HL", barindex-x, low[x])
    x=x-1
    Endif
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // Output signal bar on chart
    if close>LH and close[1]<=LH then
    result=1
    DRAWARROWUP(barindex, low)coloured(0,255,0)
    x=1// exit loop
    endif
    
    if close<HL and close[1]>=HL then
    result=2
    DRAWARROWDOWN(barindex, high)coloured(255,0,0)
    x=1// exit loop
    endif
    //--------------------------------------------------------------------------------------
    // reset these counters before re-loooping...
    LH=99999999
    HL=0
    wend
    return result as "Result"//, LatestHL as "HL",LatestLH as "LH", close as "Close"
    //, ThisBarIndex as "ThisBarIndex",barindex as "Barindex"
    
    myClearBar-screen.png myClearBar-screen.png
    #83755 quote
    robertogozzi
    Moderator
    Master

    Don’t call it but embed it in your strategy so that you can debug it better with GRAPH (you can graph more variables, not just the one returned):

    DEFPARAM cumulateorders=true
    //
    x=200 // number of bars to look back through...
    LH=99999999
    HL=0
     
    LHFound=0 // flag to indicate whether the Lowest High has been found; and the routine should now look for the Highest Low
    HLFound=0 // opposite of above...
     
    // keep looping through the specified number of bars so we know which is the nearest LH or HL
    while x>1 do
    //--------------------------------------------------------------------------------------
    // Reset flags
    result=99
    //thisBarIndex=0
     
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // look for the most recent Lowest High bar LH)
    while high[x] < LH and x>0 DO // look for a new lowest high; skip when x=0
    LH=high[x] // set the latest LH
    x=x-1 // decrement the loop
    LHFound=1 // indicate that aLH has been found
    HLFound=0 // ...and that the HL has not....
    wend
     
    //--------------------------------------------------------------------------------------
    //  Output LH bar
    if LHFound then
    //Draw where the LH was found...
    x=x+1
    //ThisBarIndex=Barindex
    //DRAWTEXT("LH*", barindex-x, high[x])
    x=x-1
    //LatestLH=LH
    //LatestHL=0
    Endif
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // look for the most recent Highest Low bar (HL)
    WHILE low[x] >HL and x>0 DO// look for a new highest low; skip when x=0
    HL=low[x]// set the latest HL
    x=x-1 // decrement the loop
    HLFound=1 // indicate that a HL has been found
    LHFound=0 // ...and that the LH has not....
    WEND
     
    //--------------------------------------------------------------------------------------
    //  Output HL bar
    if HLFound then
    // Draw where the HL was found...
    x=x+1
    //LatestHL=HL
    //LatestLH=0
    //ThisBarIndex=Barindex
    //DRAWTEXT("HL", barindex-x, low[x])
    x=x-1
    Endif
    //--------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------
    // Output signal bar on chart
    if close>LH and close[1]<=LH then
    result=1
    //DRAWARROWUP(barindex, low)coloured(0,255,0)
    x=1// exit loop
    endif
     
    if close<HL and close[1]>=HL then
    result=2
    //DRAWARROWDOWN(barindex, high)coloured(255,0,0)
    x=1// exit loop
    endif
    //--------------------------------------------------------------------------------------
    // reset these counters before re-loooping...
    LH=99999999
    HL=0
    wend
    //
    Graph Result
    if Result=1  Then
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    If Result=2 THEN
        SELL AT MARKET
    ENDIF
    Nicolas thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Function Call to user-indicator returning no data


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
TimH @timh Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
7 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/29/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...