Okay, here's a breakdown of what this MetaTrader script does, explained in a way that doesn't require any programming knowledge:
Overall Purpose:
This script is designed to automatically open and close trades (buy or sell orders) in the Forex market based on a set of predefined rules and conditions. It aims to identify potential trading opportunities based on price levels and time-based criteria. It also includes a trailing stop mechanism to protect profits.
Here's how it works, step by step:
-
Configuration (External Variables):
- The script starts by letting you, the user, set several key parameters. These are like knobs and dials that control how the script behaves.
Y
: a value related to calculating the stop loss and take profit of a tradeTrailingStop
: This sets the distance (in points) that the stop loss will follow the price to lock in profits.Period_1
: sets the period of time to calculate the Open and Close price that later will be used to evaluate if the conditions to open a trade are metPeriod_3
: sets the period of time to calculate the Open, Close, High and Low prices that later will be used to evaluate if the conditions to open a trade are metCloseTimeMin_1
: defines how long a trade can remain open before closing it to secure profits, measured in secondsCloseHour
,CloseMim_1
,CloseMim_2
: These define a specific time window (hour and minutes) on Fridays when all open trades should be closed.OpenMim_0
,OpenMim_1
,OpenMim_2
,OpenMim_3
: are specific minutes of an hour that the script will evaluate to open trades.ExtMaxRisk
: A percentage of your account balance that the script is allowed to risk on any single trade.
- The script starts by letting you, the user, set several key parameters. These are like knobs and dials that control how the script behaves.
-
Calculating Key Price Levels:
- The script calculates support and resistance levels. Think of these as potential "floors" and "ceilings" for the price. It uses the high, low, and closing prices from the previous week to calculate these levels (referred to as OP, R1, S1, R2, S2, etc.). These levels are used to determine entry points and stop losses for trades.
-
Checking Conditions Before Trading:
- Before opening any trades, the script checks a few things:
- Sufficient Data: It makes sure there's enough historical price data available.
- Trading Allowed: It verifies that trading is currently allowed by your broker.
- Sufficient Margin: It confirms that you have enough available funds in your account to cover the potential margin requirements of a trade.
- Before opening any trades, the script checks a few things:
-
Identifying Trading Opportunities and Opening Trades:
- This is the core of the script. It looks for specific patterns and conditions based on the price levels calculated earlier.
- Time-Based Entry: The script only considers opening new trades at specific minutes of the hour (defined by
OpenMim_0
,OpenMim_1
,OpenMim_2
,OpenMim_3
). - Price Action Analysis: It examines the relationship between the current price and the calculated support and resistance levels, and previous period prices. It also analizes some conditions based on previous periods high and low values.
- Order Placement: If the conditions are met, the script automatically opens a buy or sell order. It calculates the appropriate trade volume based on your account balance and risk settings. It also sets a stop-loss level (to limit potential losses) and a take-profit level (to automatically close the trade when a certain profit is reached).
- Time-Based Entry: The script only considers opening new trades at specific minutes of the hour (defined by
- This is the core of the script. It looks for specific patterns and conditions based on the price levels calculated earlier.
-
Managing Open Trades:
- Once a trade is open, the script continues to monitor it.
- Time-Based Closing: If a trade has been open for longer than a set amount of time (
CloseTimeMin_1
) and is profitable, the script will automatically close it to secure the profits. - Friday Closing: On Fridays, during a specified time window (
CloseHour
,CloseMim_1
,CloseMim_2
), the script will close all open trades, regardless of their profit or loss. - Trailing Stop: This is a dynamic stop-loss. As the price moves in a favorable direction, the stop-loss is automatically adjusted to lock in profits. The
TrailingStop
parameter determines how closely the stop-loss follows the price.
- Time-Based Closing: If a trade has been open for longer than a set amount of time (
- Once a trade is open, the script continues to monitor it.
In Simple Terms:
Imagine this script as a robot trader that:
- Uses a specific strategy based on calculated support and resistance levels.
- Only enters trades at certain times.
- Automatically manages those trades by:
- Closing them after a certain time or on Fridays.
- Adjusting the stop-loss to protect profits as the price moves in the right direction.
Important Considerations:
- Risk: Trading Forex involves risk. The script's risk settings (like
ExtMaxRisk
) are crucial for controlling your potential losses. - Market Conditions: The script's strategy may work well in some market conditions but not in others. It's important to understand the strategy and how it might perform in different scenarios.
- Testing: It is highly recommended to test any automated trading script thoroughly on a demo account before using it with real money.
//+---------------------------------------------------------+
//| FitFul_13.mq4 |
//| Copyright © 2006, AS-Bisiness Corp. |
//| Artapov Alexandr, Sidorina Yulia |
//+---------------------------------------------------------+
#property copyright "Copyright © 2006, AS-Bisiness Corp."
//----
extern double Y=15.5;
extern double TrailingStop=30;
extern int Period_1=PERIOD_H1;
extern int Period_3=PERIOD_M15;
extern int CloseTimeMin_1 =172800;
extern int CloseHour =21;
extern int CloseMim_1 =50;
extern int CloseMim_2 =59;
extern int OpenMim_0 =0;
extern int OpenMim_1 =15;
extern int OpenMim_2 =30;
extern int OpenMim_3 =45;
//----
double HW,LW,CW;
double OP,R1,R2,R3,S1,S2,S3,S05,S15,S25,R05,R15,R25;
int _GetLastError=0;
//+------------------------------------------------------------------+
double MarginCalculate(string symbol,double volume)
{
string first =StringSubstr(Symbol(),0,3);
string second =StringSubstr(Symbol(),3,3);
string currency=AccountCurrency();
double leverage=AccountLeverage();
double contract=MarketInfo(Symbol(),MODE_LOTSIZE);
double bid =MarketInfo(Symbol(),MODE_BID);
//---- äîïóñêàåì òîëüêî ñòàíäàðòíûå ôîðåêñíûå ñèìâîëû XXXYYY
if(StringLen(Symbol())!=6)
{
Print("MarginCalculate: '",first+second,"' must be standard forex symbol XXXYYY");
return(0.0);
}
//---- ïðîâåðêà íàëè÷èÿ äàííûõ
if(bid<=0 || contract<=0)
{
Print("MarginCalculate: no market information for '",first+second,"'");
return(0.0);
}
//---- ïðîâåðÿåì ñàìûå ïðîñòûå âàðèàíòû - áåç êðîññîâ
if(first==currency) return(contract*volume/leverage); // USDxxx
if(second==currency) return(contract*bid*volume/leverage); // xxxUSD
//---- ïðîâåðÿåì îáû÷íûå êðîññû, èùåì ïðÿìîå ïðåîáðàçîâàíèå ÷åðåç âàëþòó äåïîçèòà
string base=currency+first; // USDxxx
if(MarketInfo(base,MODE_BID)>0) return(contract/MarketInfo(base,MODE_BID)*volume/leverage);
//---- ïîïðîáóåì íàîáîðîò
base=first+currency; // xxxUSD
if(MarketInfo(base,MODE_BID)>0) return(contract*MarketInfo(base,MODE_BID)*volume/leverage);
//---- íåò âîçìîæíîñòè ïðÿìîãî ïåðåðàñ÷åòà
Print("MarginCalculate: can not convert '",first+second,"'");
return(0.0);
}
//--- extern variables
extern double ExtMaxRisk=0.05;
//--- calculate current volume
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double CalcVol()
{
double lot_min =MarketInfo(Symbol(),MODE_MINLOT);//0.1;
double lot_max =MarketInfo(Symbol(),MODE_MAXLOT);//5.0;
double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP);//0.1;
double vol;
//----
if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0)
{
Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
return(0);
}
if(AccountLeverage()<=0)
{
Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
return(0);
}
//--- basic formula
vol=NormalizeDouble(AccountFreeMargin()*ExtMaxRisk/AccountLeverage()/10.0,2);
//--- additional calculation
int orders=HistoryTotal();
int losses=0;
if(AccountBalance()>0)
{
for(int m=orders-1;m>=0;m--)
{
if(OrderSelect(m,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) vol=NormalizeDouble(vol-lot_step,1);
}
//---
vol=NormalizeDouble(vol/lot_step,0)*lot_step;
if(vol<lot_min) vol=lot_min;
if(vol>lot_max) vol=lot_max;
//---
return(vol);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double bid =MarketInfo(Symbol(),MODE_BID);
double ask =MarketInfo(Symbol(),MODE_ASK);
double point =MarketInfo(Symbol(),MODE_POINT);
int digits =MarketInfo(Symbol(),MODE_DIGITS);
double slip =MarketInfo(Symbol(),MODE_STOPLEVEL);
//========Âû÷èñëåíèå íåäåëüíûõ óðîâíåé============
double HW=iHigh(Symbol(),PERIOD_W1,1);
double LW=iLow(Symbol(),PERIOD_W1,1);
double CW=iClose(Symbol(),PERIOD_W1,1);
//----
double OP= NormalizeDouble((HW+LW+CW)/3,digits);
double R1= NormalizeDouble(2*OP-LW,digits);
double S1= NormalizeDouble(2*OP-HW,digits);
double R05=NormalizeDouble((OP+R1)/2,digits);
double S05=NormalizeDouble((OP+S1)/2,digits);
double R2= NormalizeDouble(OP+(HW-LW),digits);
double S2= NormalizeDouble(OP-(HW-LW),digits);
double R15=NormalizeDouble((R1+R2)/2,digits);
double S15=NormalizeDouble((S1+S2)/2,digits);
double R3= NormalizeDouble(2*OP+(HW-2*LW),digits);
double S3= NormalizeDouble(2*OP-(2*HW-LW),digits);
double R25=NormalizeDouble((R2+R3)/2,digits);
double S25=NormalizeDouble((S2+S3)/2,digits);
int total=OrdersTotal(),ticket,i=0,a=0,flag=0,k=0;
//----
if(total<1)
{
if(Bars<100 || IsTradeAllowed()==false)
{Print("Íåäîñòàòî÷íî Áàðîâ - = ", BarsPerWindow());
return;
}
if (AccountFreeMargin()<MarginCalculate(Symbol(),1.0))
{
Print("Ðàáîòàòü íåëüçÿ -ÍÅÒ ÄÅÍÅÃ- = ", MarginCalculate(Symbol(),1.0));
return;
}
}
RefreshRates();
//======Îïðåäåëåíèå ïåðåìåííûõ íåîáõîäèìîãî áàðà=======
double O1_b1=iOpen(Symbol(),Period_1,1);
double C1_b1=iClose(Symbol(),Period_1,1);
double O2_b1=iOpen(Symbol(),Period_1,2);
double C2_b1=iClose(Symbol(),Period_1,2);
double O1_b3=iOpen(Symbol(),Period_3,1);
double C1_b3=iClose(Symbol(),Period_3,1);
double L2_b3=iLow(Symbol(),Period_3,2);
double C2_b3=iClose(Symbol(),Period_3,2);
double L3_b3=iLow(Symbol(),Period_3,3);
double C3_b3=iClose(Symbol(),Period_3,3);
double H2_b3=iHigh(Symbol(),Period_3,2);
double H3_b3=iHigh(Symbol(),Period_3,3);
//=================================
if (total>0)
while(a<=total)
{ if (OrderSelect(a, SELECT_BY_POS)==true)
{ if (OrderSymbol()==Symbol()) k++;
if (k==3) {flag=1; break;}
}
a++;
}
//================================================
if(flag==0)
{
if((Minute()== OpenMim_0)||(Minute()== OpenMim_1)||(Minute()== OpenMim_2)||(Minute()== OpenMim_3))
{
//11111111111111111111111111111111111111
if (O1_b1<=C1_b1)
{
if(O2_b1<=OP && C2_b1>=OP)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S1-Y*point,digits),
NormalizeDouble(R1+Y*point,digits),"0B",100,0,Lime);
Print( "MagicNum=",OrderMagicNumber(), " OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=R05 && C2_b1>=R05)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S05-Y*point,digits),
NormalizeDouble(R15+Y*point,digits),"1B",101,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=R1 && C2_b1>=R1)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(OP-Y*point,digits),
NormalizeDouble(R2+Y*point,digits),"2B",102,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=R15 && C2_b1>=R15)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R05-Y*point,digits),
NormalizeDouble(R25+Y*point,digits),"3B",103,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=R2 && C2_b1>=R2)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R1-Y*point,digits),
NormalizeDouble(R3+Y*point,digits),"4B",104,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=R25 && C2_b1>=R25)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R15-Y*point,digits),
NormalizeDouble(R3+Y*point,digits),"5B",105,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=S1 && C2_b1>=S1)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S2-Y*point,digits),
NormalizeDouble(OP+Y*point,digits),"7B",107,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1<=S05 && C2_b1>=S05)
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S15-Y*point,digits),
NormalizeDouble(R05+Y*point,digits),"8B",108,0,Lime);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ",GetLastError() );return(-1);
return(0);
}
}
// - ÏÐÎÁÎÉ (ÂÂÅÐÕÓ ÑÍÈÇ)!!!
if (O1_b1>=C1_b1)
{
if(O2_b1>=OP && C2_b1<=OP)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R1+Y*point,digits),
NormalizeDouble(S1-Y*point,digits),"0S",200,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=S05 && C2_b1<=S05)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R05+Y*point,digits),
NormalizeDouble(S15-Y*point,digits),"1S",201,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=S1 && C2_b1<=S1)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(OP+Y*point,digits),
NormalizeDouble(S2-Y*point,digits),"2S",202,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=S15 && C2_b1<=S15)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(S05+Y*point,digits),
NormalizeDouble(S25-Y*point,digits),"3S",203,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=S2 && C2_b1<=S2)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(S1+Y*point,digits),
NormalizeDouble(S3-Y*point,digits),"4S",204,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=S25 && C2_b1<=S25)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(S15+Y*point,digits),
NormalizeDouble(S3-Y*point,digits),"5S",205,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=R1 && C2_b1<=R1)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R2+Y*point,digits),
NormalizeDouble(OP-Y*point,digits),"7S",207,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if(O2_b1>=R05 && C2_b1<=R05)
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R15+Y*point,digits),
NormalizeDouble(S05-Y*point,digits),"8S",208,0,Red);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
}
// - ÎÒÁÎÉ (ÑÂÅÐÕÓ ÂÍÈÇ È ÂÂÅÐÕ)!!!
if (O1_b3<=C1_b3)
{
if((L3_b3<=OP && C3_b3>=OP)&& (L2_b3<=OP && C2_b3>=OP))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S1-Y*point,digits),
NormalizeDouble(R1+Y*point,digits),"8B",300,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=R05 && C3_b3>=R05)&& (L2_b3<=R05 && C2_b3>=R05))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S05-Y*point,digits),
NormalizeDouble(R15+Y*point,digits),"9B",301,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=R1 && C3_b3>=R1)&& (L2_b3<=R1 && C2_b3>=R1))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(OP-Y*point,digits),
NormalizeDouble(R2+Y*point,digits),"10B",302,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=R15 && C3_b3>=R15)&& (L2_b3<=R15 && C2_b3>=R15))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R05-Y*point,digits),
NormalizeDouble(R25+Y*point,digits),"11B",303,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=R2 && C3_b3>=R2)&& (L2_b3<=R2 && C2_b3>=R2))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R1-Y*point,digits),
NormalizeDouble(R3+Y*point,digits),"12B",304,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=R25 && C3_b3>=R25)&& (L2_b3<=R25 && C2_b3>=R25))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(R15-Y*point,digits),
NormalizeDouble(R3+Y*point,digits),"13B",305,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=S1 && C3_b3>=S1)&& (L2_b3<=S1 && C2_b3>=S1))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S2-Y*point,digits),
NormalizeDouble(OP+Y*point,digits),"15B",307,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((L3_b3<=S05 && C3_b3>=S05)&& (L2_b3<=S05 && C2_b3>=S05))
{
ticket=OrderSend(Symbol(),OP_BUY,CalcVol(),ask,slip,NormalizeDouble(S15-Y*point,digits),
NormalizeDouble(R05+Y*point,digits),"16B",308,0,PaleGreen);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
}
// - ÎÒÁÎÉ (ÑÍÈÇÓ ÂÂÅÐÕ È ÂÍÈÇ)!!!
if (O1_b3>=C1_b3)
{
if((H3_b3>=OP && C3_b3<=OP) && (H2_b3>=OP && C2_b3<=OP))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R1+Y*point,digits),
NormalizeDouble(S1-Y*point,digits),"8S",400,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=S05 && C3_b3<=S05) && (H2_b3>=S05 && C2_b3<=S05))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R05+Y*point,digits),
NormalizeDouble(S15-Y*point,digits),"9S",401,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=S1 && C3_b3<=S1) && (H2_b3>=S1 && C2_b3<=S1))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(OP+Y*point,digits),
NormalizeDouble(S2-Y*point,digits),"10S",402,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=S15 && C3_b3<=S15) && (H2_b3>=S15 && C2_b3<=S15))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(S05+Y*point,digits),
NormalizeDouble(S25-Y*point,digits),"11S",403,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=S2 && C3_b3<=S2) && (H2_b3>=S2 && C2_b3<=S2))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(S1+Y*point,digits),
NormalizeDouble(S3-Y*point,digits),"12S",404,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=S25 && C3_b3<=S25) && (H2_b3>=S25 && C2_b3<=S25))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),ask,slip,NormalizeDouble(S15+Y*point,digits),
NormalizeDouble(S3-Y*point,digits),"13S",405,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=R1 && C3_b3<=R1) && (H2_b3>=R1 && C2_b3<=R1))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R2+Y*point,digits),
NormalizeDouble(OP-Y*point,digits),"15S",407,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
if((H3_b3>=R05 && C3_b3<=R05) && (H2_b3>=R05 && C2_b3<=R05))
{
ticket=OrderSend(Symbol(),OP_SELL,CalcVol(),bid,slip,NormalizeDouble(R15+Y*point,digits),
NormalizeDouble(S05-Y*point,digits),"16S",408,0,Salmon);
Print( "MagicNum=",OrderMagicNumber()," OrderSend ¹ ", GetLastError());return(-1);
return(0);
}
}
}
}
//-------------------------------------------------------------
for(i=0;i<=total;i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()&& IsTradeAllowed()==true)
{
if(OrderType()==OP_BUY)
{
if(CurTime()-OrderOpenTime() >CloseTimeMin_1 && OrderProfit( )>=0)
{
OrderClose(OrderTicket(),OrderLots(),bid,slip,Violet);
Sleep(10000);continue;
}
if (DayOfWeek()== 5 && (Hour()==CloseHour && Minute()>=CloseMim_1 && Minute()<=CloseMim_2))
{
OrderClose(OrderTicket(),OrderLots(),ask,slip,Violet);
Sleep(10000);continue;
}
if(TrailingStop>0)
{
if(bid-OrderOpenPrice()>point*TrailingStop)
{
if(OrderStopLoss()<bid-point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+TrailingStop*point,OrderTakeProfit(),0,Moccasin);
Sleep(10000);return(0);
}
}
}
}
else
{
if(OrderType()==OP_SELL)
{
if(CurTime()-OrderOpenTime() >CloseTimeMin_1 && OrderProfit( )>=0)
{
OrderClose(OrderTicket(),OrderLots(),ask,slip,Violet);
Sleep(10000);continue;
}
if (DayOfWeek()== 5 && (Hour()==CloseHour && Minute()>=CloseMim_1 && Minute()<=CloseMim_2))
{
OrderClose(OrderTicket(),OrderLots(),ask,slip,Violet);
Sleep(10000);continue;
}
if((OrderOpenPrice()-ask)>(point*TrailingStop))
{
if((OrderStopLoss()>(ask+point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-TrailingStop*point,OrderTakeProfit(),0,Moccasin);
Sleep(10000);return(0);
}
}
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments