
Continuing to answer your requests for the hotkeys.
10. A hotkey that prompts the user to enter an ATR. With this ATR, is it possible to create an automatic trigger order based on the entry price, where it sells 1 ATR above the price filled, and the stop is 1 ATR below the price filled. Also, was wondering if the functionality could work during premarket, since that's something I wasn't able to figure out, but I know you've worked on. Currently, i have a macro pad of all different ATRs, and a bunch of different hotkeys for that, so I locate the shares based on a calculation of risk, and then choose a hotkey that creates orders based on whatever the ATR is. But, updating these to take on more risk is a pain, since I have to go through and update each ATR manually. Would love your help here!
The ATR can be read from the indicator/study so you do not need to enter it, anyway if you do, it is a matter of setting the stop to the distance of the ATR.
prompt for the ATR
short as you usually do with a go short entry hotkey
set the stop to the calculated ATR distance with this hotkey
$MONTAGE.exechotkey("ALRTDELALL"); if ($montage.pos>0) { $MONTAGE CXL ALLSYMB; $CLICKEDSTOP=$MONTAGE.Avgcost+$MYATR; setvar("MYSTOP_"+$MONTAGE.SYMBOL,$MONTAGE.PRICE); $MYALERT=NewAlertObj(); $MYALERT.name="Clickedstop "+SYMB; if($MYPOS>0) { $MYALERT.AddItem("Last Sale","<",$CLICKEDSTOP); } if($MYPOS<0) { $MYALERT.AddItem("Last Sale",">",$CLICKEDSTOP); } //test if symbol is on SSR if (getquoteobj($MONTAGE.SYMBOL).SSR==1) { //call SSR exit hotkey $MYALERT.Script="$montage.symbol="+$MYSYMB+";$montage.exechotkey\(\"Exit\"\);"; } else { //call standard exit hotkey $MYALERT.Script="$montage.symbol="+$MYSYMB+";$montage.exechotkey\(\"Exit\"\);"; } $MYALERT.Speak=0; $MYALERT.SYMB=$MYSYMB; $MYALERT.PlaySound=0; $MYALERT.Autodelete=1; $MYALERT.Loop=0; $MYALERT.PopupWindow=1; $MYALERT.save(); }
11. Trailing stop that maintains the same percentage as the stock price changes.
If this is being meant to set a trailing stop to something like current price with an offset of 1% meaning for $100 price trail from $99 while at $150 the trail would be at 148.50, I wrote about possible 2 solutions.
Virtually think about it like you set the trailing stop to a variable which is changing. You know that you want to get out whatever the value of the variable is. So all that is left to do is to set the trailing stop and let the variable update in time (on the alert) automatically only when it changes to the upside (for longs). The TRAILINGSTOP variable can be updated in a chart update script by calculating the offset like
if($TRAILINGSTOP<$MONTAGE.LAST*0.99)
{
if(isobj(GetAlertObj("TRAILstop "+SYMB)))
{
$TRAILINGSTOP=$MONTAGE.LAST*0.99;
$MYALERT.ResetItem();
$MYALERT.AddItem("Last Sale","<",$TRAILINGSTOP);
$MYALERT.save();
}
}
which gives you exactly your 1% percent trailing stop. See the next question too.
12. One hotkey (ctrl b) to enter a premarket trade at ask+.03, set a stoploss at 10% below entry, add Ave price horizontal line, and 20% trailing stop loss - all with one hotkey - using no montage names, no chart clicking and no hot buttons
This one is interesting because at a certain time the trailing stop will go higher than the static stop. That is not a problem if you use alerts as stops with standard exit hotkeys as they will not do any harm if your position is 0 already. What will be challenging is the cleanup of the created alerts.
You need to name your montage window and your chart window.
// edit the window names
$montage=getwindowobj("MONTAGE1");
$my1minwindow=getwindowobj("MY1MIN");
// cancel existing orders
$montage. CXL ALLSYMB;
// buy
$buyprice=Ask+0.03;
$mystop=round($montage.ask*0.9,2);
if($mystop<1)
{
$mystop=round($montage.ask*0.9,4);
}
$montage.Price=$buyprice;Price=ROUND2;
$montage.BUY=Send;
// wait for the fill
wait(2000);
// delete all lines before drawing new average
$my1minwindow.RemoveALLLines;
// draw the avgcost line simplified
$my1minwindow.DrawHorzLineWithPrice($MONTAGE.AVGCOST,color(190,254,152));
// static stop at 10% offset
// delete old stops first
$loop=10;
while ($loop>=0)
{
$TODELALERT=GetAlertObj("Clickedstop "+SYMB);
if (IsObj($TODELALERT))
{
$TODELALERT.delete();
}
$loop=$loop-1;
}
// set the new stop
$MYPOS=GetAccountObj($MONTAGE.ACCOUNT).getposition($montage.symbol).share;
if ($montage.pos>0)
{
$MONTAGE CXL ALLSYMB;
$CLICKEDSTOP=$MYSTOP;
setvar("MYSTOP_"+$MONTAGE.SYMBOL,$MONTAGE.PRICE);
$MYALERT=NewAlertObj();
$MYALERT.name="Clickedstop "+SYMB;
$MYALERT.AddItem("Last Sale","<",$CLICKEDSTOP);
//call standard exit hotkey
$MYALERT.Script="$montage.symbol="+$MYSYMB+";$montage.exechotkey\(\"Exit\"\);";
$MYALERT.Speak=0;
$MYALERT.SYMB=$MYSYMB;
$MYALERT.PlaySound=0;
$MYALERT.Autodelete=1;
$MYALERT.Loop=0;
$MYALERT.PopupWindow=1;
$MYALERT.save();
}
// TRAIL stop
// delete old stops
$loop=10;
while ($loop>=0)
{
$TODELALERT=GetAlertObj("TRAILstop "+SYMB);
if (IsObj($TODELALERT))
{
$TODELALERT.delete();
}
$loop=$loop-1;
}
// create new stop
$TRAILSTOP=$MONTAGE.AVGCOST*0.8;
$MYALERT=NewAlertObj();
$MYALERT.name="TRAILstop "+SYMB;
$MYALERT.AddItem("Last Sale","<",$TRAILSTOP);
$MYALERT.Script="$montage.symbol="+$MYSYMB+";$montage.exechotkey\(\"Exit\"\);";
$MYALERT.Speak=0;
$MYALERT.SYMB=$MYSYMB;
$MYALERT.PlaySound=0;
$MYALERT.Autodelete=1;
$MYALERT.Loop=0;
$MYALERT.save();
This enters the trade and sets the alerts. Now you need to keep the TRAILSTOP variable to be updated, but only to the upside. You need to add this code to one of your chart update scripts to achieve that.
if($TRAILSTOP<$MONTAGE.LAST*0.8)
{
if(isobj(GetAlertObj("TRAILstop "+SYMB)))
{
$TRAILSTOP=$MONTAGE.LAST*0.8;
$MYALERT.ResetItem();
$MYALERT.AddItem("Last Sale","<",$TRAILSTOP);
$MYALERT.save();
}
}
You also need to name your standard exit hotkey as “Exit”; You can take the one from here
It would deserve some other functionality like drawing the lines where the stops are but that would be beyond your question and capacity of this post. For management of the alerts keep the alerts window opened.
13. One key that will autolocate shares and then short on bid or ask!
There you go.
//your Buying Price
$MYBP=100;
//Your max price per share for the locates
$MYMAXPRICE=0.02*$MYBP;
$MONTAGE=GetWindowObj("MONTAGE1");
$MONTAGE.Cxl AllSymb;
$MONTAGE.Share=$MYBP/$MONTAGE.LAST;
$MONTAGE.AutoLocateMaxPrice=$MYMAXPRICE;
$MONTAGE.AutoLocate;
Wait(5000);
$MONTAGE.Route="LIMIT";
$MONTAGE.Price=$MONTAGE.Ask;
$MONTAGE.Share=$MONTAGE.Located;
$MONTAGE.TIF="DAY+";
// This prevents the order from executing.
//$MONTAGE.Load;
// This will execute it if you uncomment it
$MONTAGE.Sell;
Stay tuned for more…