This one came as a request from one of my readers. It contains several interesting techniques like finding the candle which made the low of the day or adding a condition before making the alert.
The goal is to alert the trader when a stock is breaking the LOD, but not always. It needs to alert only when there was a pullback before making the new LOD.
How it works
It determines how many candles have been drawn so far from the market open.
It finds the candle that made the LOD today. For example, candle -15 means 15 candles ago the LOD has been set. This is getting tested every second so when a new candle is drawn and no new LOD has been set the $MYLOD value changes to -16 then to -17 etc.
Then, on a button press, we create an alert that monitors the global variable $MYLOD for a change since we last pressed the button. So if we set the alert when the LOD was set by candle -15 we will monitor if $MYLOD is still -15 or lower and when it gets changed to 0 which is the highest value possible
there is a check if the LOD has been set at least -3 candles ago in the button so that it does not allow us to set the LOD alert for a break of LOD that happened only a while ago. This ensures that there was a pullback before the new LOD was set.
Why so complicated?
one would think that I could just read the LOD and store its value into a variable, then on every change of that variable value I can call the alert. This would work, of course, but on a trending stock it would just alert you all the time.
This is intended for situations when there is a slight pull back before the LOD is broken.
Also with this approach we do not need to know exactly where the LOD is. So we can use this code for trade automation without knowing what the traded symbol is or how the chart looks like, this is more universal.
Requirements
Named windows
Montage window named MONTAGE1
2-min chart window named MY2MINCHART
Startup Scripts
LOD Index Finder hotkey
//define start of the day
$MINTIME=34200;
//we use 2-min chart
$CHARTTIME=2;
$MYCHARTWINDOW=GetWindowObj("MY2MINCHART");
$TIMENOW=getsecond();
$INDEX=-1;
$LO=LAST;
//count the time difference
$TIMEDIFF=$TIMENOW-$MINTIME;
//calculate number of candles-cycles from the start of the day
$NROFCANDLES=$TIMEDIFF/60/$CHARTTIME;
while($INDEX>0-$NROFCANDLES)
{
$TIMETHEN=$TIMENOW+$INDEX*$CHARTTIME*60;
if ($TIMETHEN<=$MINTIME)
{
return;
}
else
{
$CDLLO=$MYCHARTWINDOW.getbar($INDEX).Lo;
if($CDLLO<$LO)
{
$LO=$CDLLO;
$MYLOD=$index;
}
$INDEX=$INDEX-1;
}
}
Desktop Load script
$MONTAGE=GetWindowObj("MONTAGE1");
Timer event script
$MONTAGE.exechotkey("LODIndexFinder");
Set the Alert button script
if($MYLOD>-3)
{
MsgBox("LOD too close");
}
else
{
$MYALERT=NewAlertObj();
$MYALERT.name="LOD BREAK";
$MYALERT.AddItem("Global Variable",">","$MYLOD:"+$MYLOD);
$MYALERT.Speak=1;
$MYALERT.Symb=SYMB;
$MYALERT.Loop=0;
$MYALERT.Autodelete=1;
$MYALERT.PlaySound=0;
$MYALERT.save();
}
Bugs and Limits
2-min chart and higher needs to be used as the loop limit is 200, which covers the market hours closely.
It has to be run on a stock that draws a candle every timeframe. On inactive stocks not drawing candles, it cannot calculate properly the look-back and will give wrong LOD results.
The Autodelete=1 in the alert is there because the Loop=0 does not work in current version of DAS Trader 5.8.0.2. In the next version we could keep the alert if we need to
Tunables
$MINTIME=34200;
Means we start counting candles from 9:30 AM only. We can put different time in seconds from midnight to shorten the look-back
we can use different time-frame charts. Higher than 2-min. needs to change the
//we use 2-min chart
$CHARTTIME=2;
accordingly, for the look-back.
To tune the minimum number of candles for the pullback, for enabling the alert, we can tune the
if($MYLOD>-3)
to a different value.
How to test
we can either set a low look back in the $MINTIME to a few minutes and watch the break of the lowest candle
Or we can switch the chart to a different symbol that set the LOD later than our symbol that we set the alert on. For example, if TSLA 0.00%↑ set the low of the day -80 candles ago and AAPL 0.00%↑ -60 candles ago, switching the symbol to AAPL 0.00%↑ will trigger the alert in 1 second. If we switch to a symbol that set the LOD sooner, like -81 candles ago (or sooner after the market open) it will not trigger.
Other considerations
This could be achieved also with a simple LOD alert that would then run the whole logic of testing if the event is the one we are looking for. Currently as of version 5.8.0.1 stable and 5.8.0.2 beta the alerts in DAS Trader Pro are buggy and when there will be a version with fixes released, I will be covering the use cases in a separate article.
hi peter great stuff i got so many hot keys and configurations in my das platform thanks to you !!
question,
i do have 3 different montage windows, any chance to do universal hotkey alert for LOD and HOD by instead of doing 3 different hotkey ? when im live sometime its hard for me to check which montage# window i am and preferred just double press on the chart im intend to use hot key for.
thanks in advance !