marketposition and entryprice not updating with a "buy" .  [SOLVED]

Questions about MultiCharts and user contributed studies.
bjornc
Posts: 18
Joined: 11 Dec 2013
Has thanked: 4 times
Been thanked: 2 times

marketposition and entryprice not updating with a "buy" .

Postby bjornc » 09 Jun 2015

hi,

Code: Select all

if (lasttrade >=0 and ema41 > ema8 and Price < lastpivolow and tr < trAvarage) then
begin

if (MarketPosition >= 0 or firsttime = True) then
begin
sellshort("bjoshort") TradeSize contracts next bar at open;
//buy("sellstopTradeSize contracts next bar at EntryPrice +tr Stop;
firsttime = false;
ownstoploss = entryprice(0)+(trmax);
print("short ","lastpiviotlow ",lastpivolow,"marketpos:",MarketPosition(0),firsttime,"currentbar ",currentbar,"tr avarage ",trAvarage:8:8,"tr ",tr:8:8,"trmax ",trmax:8:8, "entryprice",entryprice(0):8:8,"ownstoploss ",ownstoploss:8:8 );
lasttrade = -1;

end;
end;
if (lasttrade <=0 and ema41 < ema8 and Price >lastpivohigh and tr < trAvarage) then
begin

if (MarketPosition <=0 or firsttime = True) then
begin

buy("bjolong") TradeSize contracts next bar at open;
//sell("buystop")TradeSize contracts next bar at EntryPrice-tr Stop;
firsttime = false;
ownstoploss = entryprice(0)-(trmax) ;
print("long ","lastpiviothigh ",lastpivohigh,"marketpos:",MarketPosition(0),firsttime,"currentbar ",currentbar,"tr avarage ",trAvarage:8:8,"tr ",tr:8:8,"trmax ",trmax:8:8, "entryprice",entryprice(0):8:8,"ownstoploss ",ownstoploss:8:8 );
lasttrade = 1;
end;
end;
results in this :

Code: Select all

long lastpiviothigh 1.09marketpos: 0.00FALSEcurrentbar 96.00tr avarage 0.00057487tr 0.00047143trmax 0.00144857entryprice0.00000000ownstoploss -0.00144857
short lastpiviotlow 1.12marketpos: 1.00FALSEcurrentbar 600.00tr avarage 0.00103027tr 0.00102357trmax 0.00296643entryprice1.08845000ownstoploss 1.09141643
long lastpiviothigh 1.11marketpos: 0.00FALSEcurrentbar 884.00tr avarage 0.00101160tr 0.00100786trmax 0.00296643entryprice0.00000000ownstoploss -0.00296643
short lastpiviotlow 1.13marketpos: 1.00FALSEcurrentbar 1191.00tr avarage 0.00101160tr 0.00066643trmax 0.00296643entryprice1.11942000ownstoploss 1.12238643
long lastpiviothigh 1.12marketpos: 0.00FALSEcurrentbar 1479.00tr avarage 0.00104940tr 0.00059786trmax 0.00310857entryprice0.00000000ownstoploss -0.00310857
short lastpiviotlow 1.14marketpos: 1.00FALSEcurrentbar 1942.00tr avarage 0.00104940tr 0.00103857trmax 0.00310857entryprice1.11732000ownstoploss 1.12042857
long lastpiviothigh 1.14marketpos: 0.00FALSEcurrentbar 1985.00tr avarage 0.00104940tr 0.00103857trmax 0.00310857entryprice0.00000000ownstoploss -0.00310857
short lastpiviotlow 1.13marketpos: 1.00FALSEcurrentbar 2127.00tr avarage 0.00104940tr 0.00104071trmax 0.00310857entryprice1.14391000ownstoploss 1.14701857
long lastpiviothigh 1.11marketpos: 0.00FALSEcurrentbar 2617.00tr avarage 0.00104940tr 0.00055643trmax 0.00310857entryprice0.00000000ownstoploss -0.00310857
short lastpiviotlow 1.10marketpos: 1.00FALSEcurrentbar 2723.00tr avarage 0.00104940tr 0.00049429trmax 0.00310857entryprice1.11417000ownstoploss 1.11727857
long lastpiviothigh 1.09marketpos: 0.00FALSEcurrentbar 3175.00tr avarage 0.00104085tr 0.00051500trmax 0.00310857entryprice0.00000000ownstoploss -0.00310857
short lastpiviotlow 1.10marketpos: 1.00FALSEcurrentbar 3462.00tr avarage 0.00104085tr 0.00058357trmax 0.00310857entryprice1.09080000ownstoploss 1.09390857
long lastpiviothigh 1.09marketpos: 0.00FALSEcurrentbar 3642.00tr avarage 0.00104085tr 0.00089786trmax 0.00310857entryprice0.00000000ownstoploss -0.00310857
short lastpiviotlow 1.12marketpos: 1.00FALSEcurrentbar 4022.00tr avarage 0.00110677tr 0.00053143trmax 0.00331786entryprice1.09413000ownstoploss 1.09744786
the entryprice is zero on a buy
and the market position is also 0 on a Buy order

what am i doing wrong? this is backtesting only

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

Re: marketposition and entryprice not updating with a "buy"

Postby Henry MultiСharts » 10 Jun 2015

Hello bjornc,

This code is incomplete. The snippet you have provided operates with some variables that are not being declared in what you have provided. Please output the required variable values outside of any conditionals. If you want to get assistance from the other forum members please provide the complete code and the workspace you are using.

bjornc
Posts: 18
Joined: 11 Dec 2013
Has thanked: 4 times
Been thanked: 2 times

Re: marketposition and entryprice not updating with a "buy"  [SOLVED]

Postby bjornc » 10 Jun 2015

Hello bjornc,

This code is incomplete. The snippet you have provided operates with some variables that are not being declared in what you have provided. Please output the required variable values outside of any conditionals. If you want to get assistance from the other forum members please provide the complete code and the workspace you are using.
hi,

the market position issue was a bad if else end thing.

i worked around the entryprice with just taking the current close time instead


Return to “MultiCharts”