3 Losses = Locked (Stop Revenge Trading)
The script(s) featured in this episode are provided below for educational and reference purposes. Trading stocks, options, futures, and other financial instruments involves substantial risk of loss and is not suitable for all investors. You may lose some or all of your invested capital. Always review and thoroughly test any code in a simulator before using it in a live trading environment.
This video is provided by YouTube. It is blocked until you accept functional cookies.
Important!
Some of these scripts may also rely on scripts created in previous episodes. Any
updates to scripts will be shown below, but any scripts left unchanged would need to
be sourced from the episode they were featured in. It is recommended to watch all
videos in this series in order, that way you can piece together a working system
with a good understanding of all the connected parts.
OBJECT_INIT_TRADE
This script is from a previous episode. Changes have been marked in the file so you can follow what was adjusted in this episode.
//OBJECT_INIT_TRADE
if (GetVar("$TRADE")==0) $TICKER=0;
if (!IsObj($TRADE)) $TRADE = newUserObj();
$TRADE.DAILYEMA200 = 0;
$TRADE.DAILYEMA200_LAST = 0;
$TRADE.DAILYSMA200 = 0;
$TRADE.DAILYSMA200_LAST = 0;
$TRADE.TIME_ON_TICKER = 0;
$TRADE.CHART_LAST_SYMB = "";
//+ ADDED THE FOLLOWING LINES
$TRADE.LAST_PL = 1234;
$TRADE.LAST_SHARES = 0;
$TRADE.LAST_GAIN_LOSS = 0;
$TRADE.LAST_AVERAGE = 0;
$TRADE.LAST_PER_SHARE = 0;
TIMER_PL_UPDATE (NEW) (This script was introduced in this episode)
//TIMER_PL_UPDATE
$ACCOUNT=GetAccountObj($ACCOUNT_NUMBER);
if ($ACCOUNT.Realized != $TRADE.LAST_PL && $TRADE.LAST_PL != 1234){
$TRADE.LAST_GAIN_LOSS = $ACCOUNT.Realized - $TRADE.LAST_PL;
$TRADE.LAST_PER_SHARE = 0;
if ($TRADE.LAST_SHARES > 0){
$TRADE.LAST_PER_SHARE = Round(($TRADE.LAST_GAIN_LOSS / $TRADE.LAST_SHARES), 2);
MsgLog("Per Share: " + $TRADE.LAST_PER_SHARE);
}
if ($ACCOUNT.Realized < $TRADE.LAST_PL){
//LOSS
$tmp_var_name = "$loss" + $chart_1m.SYMBOL;
if (GetVar($tmp_var_name)==0) SetVar($tmp_var_name, 0);
$this_symbol_loss = GetVar($tmp_var_name);
$this_symbol_loss = $this_symbol_loss + 1;
SetVar($tmp_var_name, $this_symbol_loss);
if ($this_symbol_loss > 2){
Speak($this_symbol_loss + " Losses " + $chart_1m.SYMBOL);
}
} else {
//GAIN
}
}
//Update PL
$TRADE.LAST_PL = $ACCOUNT.Realized;
if (IsObj($montage_window)){
$TRADE.LAST_AVERAGE = $montage_window.AVGCost;
$TRADE.LAST_SHARES = $montage_window.POS;
}
//detect current stock losses
$tmp_var_name = "$loss" + $chart_1m.SYMBOL;
if (GetVar($tmp_var_name)==0) SetVar($tmp_var_name, 0);
$this_symbol_loss = GetVar($tmp_var_name);
if (IsObj($DASHBOARD.getCustButObj("STOCK_BLOCKED"))){
if ($this_symbol_loss > 2){
$DASHBOARD.getCustButObj("STOCK_BLOCKED").Text = "BLOCKED";
$DASHBOARD.getCustButObj("STOCK_BLOCKED").BkColor = Color("Red");
} else {
$DASHBOARD.getCustButObj("STOCK_BLOCKED").Text = "";
$DASHBOARD.getCustButObj("STOCK_BLOCKED").BkColor = Color("Gray");
}
}
BUY_BY_RULES (NEW) (This script was introduced in this episode)
//BUY_BY_RULES
$TRADE.OK_TO_BUY_THIS = 1;
$TRADE.STICK_TO_PLAN_TEXT = "";
$tmp_var_name = "$loss" + $chart_1m.SYMBOL;
if (GetVar($tmp_var_name)==0) SetVar($tmp_var_name, 0);
$this_symbol_loss = GetVar($tmp_var_name);
if ($this_symbol_loss >= 3){
$TRADE.OK_TO_BUY_THIS = 0;
$TRADE.STICK_TO_PLAN_TEXT = $chart_1m.SYMBOL + " Losses 3";
}
if ($TRADE.OK_TO_BUY_THIS == 1){
//your buy script here
ExecHotkey("BUY_ASK");
} else {
MsgLog("Buy Not Allowed!");
}
MsgLog($TRADE.STICK_TO_PLAN_TEXT);
TIMER
This script is from a previous episode. Changes have been marked in the file so you can follow what was adjusted in this episode.
//TIMER
if ($TRADE.TIME_ON_TICKER > 2 && $TRADE.DAILYEMA200 == 0){
//EMA200 comes from daily chart
ExecHotkey("EMA200");
}
$bar0 = $chart_1m.GetBar(0);
ExecHotkey("ANALYZE_MACD");
ExecHotkey("DASHBOARD");
ExecHotkey("TIMER_PL_UPDATE");//+ ADDED THIS LINE
RESET_STOCK_LOSSES (NEW) (This script was introduced in this episode)
//RESET_STOCK_LOSSES
$tmp_var_name = "$loss" + $chart_1m.SYMBOL;
SetVar($tmp_var_name, 0);
Speak("Reset Losses " + $chart_1m.SYMBOL);
Disclaimer:
This is an independent project and is not affiliated with or endorsed by DASTrader.com.
The tool is currently under development and intended for educational and experimental purposes only,
including improving the experience of working with DAS hotkey scripting (e.g., code validation,
highlighting, and structure).
It does not execute trades, provide trading signals, or offer financial advice. Any scripts created or used
with DAS Trader remain the sole responsibility of the user.
Trading involves significant risk. You are fully responsible for verifying all scripts, commands, and
behavior before using them in a live trading environment.
This tool is provided “as-is” with no guarantees of accuracy, completeness, or reliability. Use at your own
risk. Always test thoroughly in a simulator before live trading.