Something wrong with the function I created

Questions about MultiCharts and user contributed studies.
Spikehog
Posts: 39
Joined: 09 Dec 2013
Has thanked: 26 times
Been thanked: 1 time

Something wrong with the function I created

Postby Spikehog » 28 Apr 2016

I created a function: DrawDown which is based on the keyword "OpenEntryMinProfit". Below is what I have written:

Code: Select all

Variables: var0( 0 );

var0 = absvalue(OpenEntryMinProfit(0)*0.02);

If Date[0] <> Date[1] or marketposition = 0 then var0 = 0;

If BarsSinceEntry = 19 then DrawDown = var0;
Then, I created another function that calulates the stop price for the short entries with the use of the DrawDown function abovementioned. This stop price is called: SX1st and the code is as following:

Code: Select all

If Date[0] <> Date[1] or marketposition = 0 then
Begin
SX1st = 0;
End;

If marketPosition = -1 and Time <= 1613 and PosTradeIsOpen(0,0) = True then
Begin
If PosTradeCount(0) = 3 and PosTradeIsOpen(0,2) = True then SX1st = AvgList(PosTradeEntryPrice(0,0), PosTradeEntryPrice(0,1), PosTradeEntryPrice(0,2)) else
If PosTradeCount(0) = 2 and PosTradeIsOpen(0,1) = True then SX1st = AvgList(PosTradeEntryPrice(0,0), PosTradeEntryPrice(0,1)) else
SX1st = PosTradeEntryPrice(0,0) + (DrawDown + 1);
End;
Here is the problem. The DrawDown was zero at one point in time within the same bar as well as same barstatus, then it went back to 29. This situation happened on every single bar after Barssinceentry>=30. I have checked every single bar since the Barssinceentry>=30. The following is the output
  • 10/3/2016 15:50:00 Barstatus> 2.00 Study>$$$ Barssinceentry 52.00 SX Price>20009.00 DrawDown> 29.00
    10/3/2016 15:50:00 Barstatus> 2.00 Study>%%% Barssinceentry 52.00 SX Price>20009.00 DrawDown> 29.00
    10/3/2016 15:50:00 Barstatus> 2.00 Study>%%% Barssinceentry 52.00 SX Price>19980.00 DrawDown> 0.00
    10/3/2016 15:50:00 Barstatus> 2.00 Study>%%% Barssinceentry 52.00 SX Price>20009.00 DrawDown> 29.00
    10/3/2016 15:50:00 Barstatus> 2.00 Study>$$$ Barssinceentry 52.00 SX Price>20009.00 DrawDown> 29.00
The change in DrawDown affects the value of SX1st which is something I didnt expect. Please advice where the problem is. Thank you!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Something wrong with the function I created

Postby Henry MultiСharts » 28 Apr 2016

Hello Spikehog,

Are you using MultiCharts or Portfolio Trader?
Who does the output - a trading signal or PMM signal?
Are you able to replicate it on one chart in offline mode/on historical data only?


Return to “MultiCharts”