FlipTradeInChannel
Download scriptThis script is designed to automatically manage and project a visual "Trade Channel" on your trading platform. Instead of requiring you to manually calculate where price levels should move based on market momentum, the tool handles the mathematical heavy lifting to keep your visual analysis updated in real-time.
How the Logic Works
1. Data Extraction The script begins by looking at a specific visual element on your chart named "TradeChannel." It identifies three primary price points and their corresponding timestamps. By analyzing these coordinates, the script understands the current shape and orientation of your trading area.
2. Trend Analysis & Momentum Calculation The tool performs two distinct types of analysis:
- Directional Identification: It determines if the current trend is bullish (upward) or bearish (downward) by comparing the relative positions of your established price points.
- Momentum Geometry: It calculates a "displacement value" based on the slope between your markers. This allows the script to determine the velocity and direction of the price movement, essentially predicting where the channel "wants" to go next.
3. Trade Alignment Check The logic compares the current market trend against the momentum of the channel. It verifies whether the price action is moving in harmony with the established trend (trading "with the flow") or if it is pushing against it. This distinction helps in maintaining a consistent visual perspective on market behavior.
4. Automatic Projection Once the calculations are complete, the script automatically updates the "TradeChannel" object on your screen. It shifts the price coordinates of all three points by the calculated displacement value.
The Practical Result
For the user, this means that as the market moves, your visual trade channel doesn't remain static; it dynamically adjusts its height and position based on the current momentum. This provides a live, automated visual guide that helps you see potential price targets and trend continuations more clearly without needing to redraw the lines manually.
//+------------------------------------------------------------------+
//| FlipTradeInChannel.mq4 |
//| Copyright © 2010, Korvin ® Co. |
//| http://alecask.narod.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Korvin ® Co."
#property link "http://alecask.narod.ru/"
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
// îïðåäåëèì ïåðåìåííûå
bool trend,potrendu;
double TP,TPbak;
string varName;
// Ïîëó÷èì óñòàíîâëåííûå ïàðàìåòðû öåíû äëÿ íàðèñîâàííîãî "TradeChannel"
double p1 = ObjectGet("TradeChannel",OBJPROP_PRICE1);
double p2 = ObjectGet("TradeChannel",OBJPROP_PRICE2);
double p3 = ObjectGet("TradeChannel",OBJPROP_PRICE3);
double t1 = ObjectGet("TradeChannel",OBJPROP_TIME1);
double t2 = ObjectGet("TradeChannel",OBJPROP_TIME2);
double t3 = ObjectGet("TradeChannel",OBJPROP_TIME3);
// Ïîëó÷èì çíà÷åíèÿ ñìåùåíèé äëÿ öåí p1, p2 è p3
bool exact = false; // íóæíà îñîáàÿ òî÷íîñòü?
int s1 = iBarShift( NULL, 0, t1, exact); // ñìåùåíèå áàðà öåíû p1
int s2 = iBarShift( NULL, 0, t2, exact); // ñìåùåíèå áàðà öåíû p2
int s3 = iBarShift( NULL, 0, t3, exact); // ñìåùåíèå áàðà öåíû p3
// Âû÷èñëèì øèðèíó òîðãîâîãî êàíàëà d è åãî çíàê
double d = (p3-p1) - (p2-p1)*(s1-s3)/(s1-s2); //
int sign = MathRound(d/MathAbs(d)); //
// ðàçáåð¸ìñÿ êàê çàäàíà òîðãîâëÿ
if (p2>=p1) trend=true; // òðåíä âîñõîäÿùèé ...
else trend=false; // èëè íèñõîäÿùèé ?
if ((trend && sign>=0)||
(!trend && sign<0)) potrendu=true; // òîðãîâëÿ ïî òðåíäó ...
else potrendu=false; // èëè ïðîòèâ òðåíäà ?
// Ïðèñâîèì íîâûå çíà÷åíèÿ öåí p1, p2 è p3 äëÿ "TradeChannel"
p1 = p1+d;
p2 = p2+d;
p3 = p3-d;
// Ïåðåäàäèì ýòè çíà÷åíèÿ â îáúåêò "TradeChannel"
while (!exact) exact = ObjectSet("TradeChannel",OBJPROP_PRICE1,p1);
exact = false;
while (!exact) exact = ObjectSet("TradeChannel",OBJPROP_PRICE2,p2);
exact = false;
while (!exact) exact = ObjectSet("TradeChannel",OBJPROP_PRICE3,p3);
return(0);
}
//+------------------------------------------------------------------+
Comments