Daydream01_v1
Download scriptThe Daydream trading script is an automated system designed to manage currency pairs by identifying price extremes and reacting to "breakout" movements. It operates by monitoring a specific window of recent market history to determine the boundaries of normal price action, then executes trades when the market pushes outside of those boundaries.
Core Trading Logic
The script functions based on three primary behaviors: identification of price channels, automated trade execution, and dynamic profit protection.
1. Price Boundary Identification The system looks back at a set number of previous candles (the "Channel Period") to establish two key benchmarks: the highest price point reached and the lowest price point reached during that timeframe. These act as the upper and lower limits of the current market "channel."
2. Entry Signals (The Breakout Strategy) The script enters the market based on whether the current price closes outside of these established boundaries:
- Buy Signal: If the current price drops below the lowest point of the recent channel, the script assumes an oversold condition and opens a "Long" position (buying with the expectation that the price will rise).
- Sell Signal: If the current price climbs above the highest point of the recent channel, the script assumes an overbought condition and opens a "Short" position (selling with the expectation that the price will fall).
3. Automated Trade Management To ensure the strategy remains organized and efficient, the script includes several automated safety protocols:
- Opposite Position Handling: If the market creates a signal to buy while a sell position is still open (or vice versa), the script will automatically close the existing trade before opening the new one. This prevents "conflicting" trades from running simultaneously.
- Time Filtering: The script includes a check to ensure it does not execute multiple orders during the exact same timeframe, preventing repetitive entries on a single price movement.
4. Dynamic Profit Protection (Trailing Stop) One of the most sophisticated features of this script is its "Trailing Profit" mechanism. Rather than simply setting a fixed target and waiting, the script actively follows the market:
- As the price moves in your favor, the system continuously recalculates the profit target to stay a set distance behind the current price.
- This allows the trade to stay open as long as the market continues to trend in the desired direction, but it will automatically trigger a closing order if the price reverses even slightly, effectively "locking in" gains during a successful run.
//+------------------------------------------------------------------+
//| Daydream by Cothool |
//| Recommended: USD/JPY 1H |
//+------------------------------------------------------------------+
#define MAGIC_NUM 48213657
//----
extern double Lots =1;
extern int ChannelPeriod=25;
extern int Slippage =3;
extern int TakeProfit =15;
//----
double LastOrderTime=0;
double CurrentDirection=0;
double CurrentTakeProfitPrice=0;
//----
void OpenLong()
{
if (Time[0]==LastOrderTime)
return;
if (CurrentDirection!=0)
return;
//----
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Blue);
LastOrderTime=Time[0];
CurrentDirection=1;
}
//----
void OpenShort()
{
if (Time[0]==LastOrderTime)
return;
if (CurrentDirection!=0)
return;
//----
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0,
"Daydream", MAGIC_NUM, 0, Red);
LastOrderTime=Time[0];
CurrentDirection=-1;
}
//----
void CloseLong()
{
int i;
if (Time[0]==LastOrderTime)
return;
if (CurrentDirection!=1)
return;
//----
for(i=0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol()==Symbol() &&
OrderMagicNumber()==MAGIC_NUM && OrderType()==OP_BUY)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3, White);
LastOrderTime=Time[0];
CurrentDirection=0;
}
}
}
//----
void CloseShort()
{
int i;
//----
if (Time[0]==LastOrderTime)
return;
if (CurrentDirection!=-1)
return;
for(i=0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol()==Symbol() &&
OrderMagicNumber()==MAGIC_NUM && OrderType()==OP_SELL)
{
OrderClose(OrderTicket(), OrderLots(), Ask, 3, White);
LastOrderTime=Time[0];
CurrentDirection=0;
}
}
}
//----
void start()
{
double HighestValue;
double LowestValue;
//
HighestValue=High[Highest(NULL, 0, MODE_HIGH, ChannelPeriod, 1)];
LowestValue=Low[Lowest(NULL, 0, MODE_LOW, ChannelPeriod, 1)];
// BUY
if (Close[0] < LowestValue)
{
CloseShort();
OpenLong();
CurrentTakeProfitPrice=Bid + TakeProfit * Point;
}
// SELL
if (Close[0] > HighestValue)
{
CloseLong();
OpenShort();
CurrentTakeProfitPrice=Ask - TakeProfit * Point;
}
// Trailing Profit Taking for Long Position
if (CurrentDirection==1)
{
if (CurrentTakeProfitPrice > Bid + TakeProfit * Point)
CurrentTakeProfitPrice=Bid + TakeProfit * Point;
if (Bid>=CurrentTakeProfitPrice)
CloseLong();
}
// Trailing Profit Taking for Short Position
if (CurrentDirection==-1)
{
if (CurrentTakeProfitPrice < Ask - TakeProfit * Point)
CurrentTakeProfitPrice=Ask - TakeProfit * Point;
if (Ask<=CurrentTakeProfitPrice)
CloseShort();
}
}
//+------------------------------------------------------------------+
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments