Here's what I have
The first 4 text lines are OK.
The problem resides with the time in trade, high since entry, low since entry and entry price.
Time in trade acts weird because all seems OK but sometimes I can see we're in a trade for the past 2 minutes and all of a sudden it goes back to 1 minute in the trade, which I don't understand why this happens.
I'm using 1 tick chart because if I use a minute chart, the high and low will always be the bar's high and low and not really the highest high and lowest low prices tested after my entry.
Also in here I'm having difficulties in retrieving these prices. Although it seems I'm always able to get the high, the low and entry are always zero.
I also tried to use the keywords to retrieve from the broker the entry time and entry price but I just can't get any information when using those keywords.
Thoughts would be much appreciated.
Here's the code
Code: Select all
[IntrabarOrderGeneration = true];
//Strategy, SA on
inputs:
ShiftBox (0),
TimeOffSet (5),
LabelSize (10),
LabelColor (lightgray),
LongColor (green),
ShortColor (red),
LabelFont ("Arial Bold");
vars:
intrabarpersist MPatB (0),
intrabarpersist prevMPatB (0),
intrabarpersist myEntrytimes (0),
intrabarpersist timeDiff (0),
intrabarpersist lastprice (close),
sessHigh (0),
sessHi (0),
sessLow (0),
sessLo (0),
priceEntry (0),
entryPrc (0),
txtStr ("Turn SA On"),
txtTime (-1),
txtContracts (-1),
txtPosition (-1),
myTime (0),
myTime2 (0),
myMinutes (0),
offSetTime (ELTimeToDateTime(TimeOffSet)),
dTick (MinMove/PriceScale),
boxShift (0),
newposition (false);
boxShift = ShiftBox * dTick;
if getappinfo(airealtimecalc) = 1 and getappinfo(aistrategyauto) = 1 then begin
MPatB = MarketPosition_at_Broker;
if MPatB <> prevMPatB and MPatB <> 0 then begin
myEntrytimes = currenttime_s;
SessHi = close;
SessLo = close;
priceEntry = close;
end;
if MPatB <> 0 then begin
if sessHi < High then sessHi = high;
if sessLo > Low then sessLo = low;
sessHigh = sessHi;
sessLow = sessLo;
priceentry = priceEntry;
//timeDiff = TimeToSeconds(Time_s) - myEntrytimeS ;
timeDiff = currentTime_s - myEntrytimeS ;
txtStr = ("account - " + text(GetAccount(1)) + newline +
newline + ifftext (MPatB < 0, " Short position", " Long position") + newline + text(MPatB) + " contract (s)" + newline +
newline + FormatTime("HH:mm:ss", el_timetodatetime_s(myEntrytimes)) + " - entry time" + NewLine +
newline + FormatTime("HH:mm:ss", el_timetodatetime_s(timediff)) + " - time in trade" + NewLine +
NumToStr(sessHigh, 2) + " - high since entry" + newline +
NumToStr(sessLow, 2) + " - low since entry" + newline +
NumToStr(priceentry , 2) + " - entry price");
end; //if LastBarOnChart_s then Print all text variables;
if MPatB = 0 then begin
txtStr = " NO POSITION ";
end;
prevMPatB = MPatB;
end;
RecalcLastBarAfter (1);
if Barnumber = 1 then begin
txtTime = text_new_s(JulianToDate(aiRightDispDateTime), GetAppInfo(aiRightDispDateTime), GetAppInfo(aiHighestDispValue) - BoxShift,"");
text_setfontname(txtTime, LabelFont);
text_setcolor(txtTime, LabelColor);
text_setsize(txtTime, LabelSize);
Text_SetStyle(txtTime, 1, 0);
//text_setborder(txtTime , true);
//text_setbgcolor(txtTime , black);
text_lock(txtTime, true);
end
else begin
text_SetString(txtTime, txtStr);
text_SetColor (txtTime, iff(MPatB = 0, LabelColor, iff(MPatB < 0,ShortColor ,LongColor)));
if BarStatus(1) = 2 then begin
Text_SetLocation_s(txtTime, JulianToDate(GetAppInfo(aiRightDispDateTime)),DateTime2ELTime_s(GetAppInfo(aiRightDispDateTime) -
offSetTime), GetAppInfo(aiHighestDispValue) - boxShift);
end;
end;