Orders Execution
0
Views
0
Downloads
0
Favorites
WOCTS_v_0_1_1
//WindOfChangeSP1TS
#property copyright "HammerLights"
#include <stderror.mqh>
#include <stdlib.mqh>
extern int StopLoss = 40; // íà÷àëüíûé ñòîïëîññ äëÿ ñòðàõîâêè
extern int StopLossReal = 5; // äèíàìè÷åñêèé ñòîïëîññ
extern int TrSt = 4; // îò êàêîé öåíû áóäåò äâèãàòüñÿ ñòîï ëîññ äâèãàòü ñòîïëîññ - òðàéëèíãñòîï
extern int Speed = 5; // Êîëè÷åñòâî ïðîéäåííûõ ïï.
extern double timeSpeed = 3; // âðåìÿ â ñåêóíäàõ.
extern double autoLots = false; // àâòîëîò.
extern double Lots = 0.01; // ëîò
double Point_;
double SL;
bool Tr;
datetime nextTime;
int cnt, total;
int up, down, TimeSpeedUp, TimeSpeedDown, Magic;
bool TimBoolUp,TimBoolDown, OrderSal;
double priceUp, priceDown;
int Get.Magic()
{
string mag;
int Magic.g;
Sleep(1000);
while (true)
{
MathSrand (TimeLocal());
mag = StringConcatenate(mag, MathRand()/15, MathRand()/8, MathRand()/32);
Magic.g = MathRound(MathAbs(StrToInteger(mag)));
mag = DoubleToStr(Magic.g,10);
if (StringLen (mag) >= 15) {Magic.g = StrToInteger(mag); break;}
}
return (MathRound(MathAbs(Magic.g)));
}
void LotsSize()
{
if(AccountBalance() < 200)
{
Lots = 0.02;
}
if(AccountBalance() > 200)
{
Lots = 0.04;
}
if(AccountBalance() > 300)
{
Lots = 0.05;
}
if(AccountBalance() > 400)
{
Lots = 0.06;
}
if(AccountBalance() > 500)
{
Lots = 0.07;
}
if(AccountBalance() > 600)
{
Lots = 0.08;
}
if(AccountBalance() > 700)
{
Lots = 0.09;
}
if(AccountBalance() > 800)
{
Lots = 0.1;
}
if(AccountBalance() > 900)
{
Lots = 0.2;
}
if(AccountBalance() > 1000)
{
Lots = 0.3;
}
if(AccountBalance() > 2000)
{
Lots = 0.4;
}
if(AccountBalance() > 3000)
{
Lots = 0.5;
}
if(AccountBalance() > 4000)
{
Lots = 0.6;
}
if(AccountBalance() > 5000)
{
Lots = 0.7;
}
if(AccountBalance() > 6000)
{
Lots = 0.8;
}
if(AccountBalance() > 7000)
{
Lots = 0.9;
}
if(AccountBalance() > 8000)
{
Lots = 1;
}
if(AccountBalance() > 9000)
{
Lots = 2;
}
if(AccountBalance() > 10000)
{
Lots = 3;
}
if(AccountBalance() > 11000)
{
Lots = 4;
}
if(AccountBalance() > 12000)
{
Lots = 5;
}
if(AccountBalance() > 13000)
{
Lots = 6;
}
if(AccountBalance() > 14000)
{
Lots = 7;
}
if(AccountBalance() > 15000)
{
Lots = 8;
}
if(AccountBalance() > 20000)
{
Lots = 9;
}
if(AccountBalance() > 30000)
{
Lots = 10;
}
if(AccountBalance() > 40000)
{
Lots = 11;
}
if(AccountBalance() > 50000)
{
Lots = 12;
}
if(AccountBalance() > 60000)
{
Lots = 13;
}
if(AccountBalance() > 70000)
{
Lots = 14;
}
if(AccountBalance() > 80000)
{
Lots = 15;
}
if(AccountBalance() > 90000)
{
Lots = 16;
}
if(AccountBalance() > 100000)
{
Lots = 17;
}
if(AccountBalance() > 110000)
{
Lots = 18;
}
if(AccountBalance() > 120000)
{
Lots = 19;
}
if(AccountBalance() > 130000)
{
Lots = 20;
}
}
void CloseOrder()
{
int tryClose;
tryClose = 0;
for(tryClose = 1; tryClose <= 2; tryClose++)
{
if(OrderClose(OrderTicket(), OrderLots(), Bid, 2,Green) == false)
{
Print("Îøèáêà ", ErrorDescription(GetLastError()));
Print("Íåâîçìîæíî çàêðûòü îðäåð, ïîïûòêà ", tryClose);
Sleep(1000);
}
else
{
break;
}
}
}
void openOrders()
{
int try;
if(autoLots == true)
{
LotsSize();
}
if(up < down)
{
Print("Ïàðàìåòð âíèç - óäîâëåòâîðÿåò óñëîâèþ");
if(TimeCurrent() - TimeSpeedDown <= timeSpeed)
{
Print("Ïàðàìåòð ÂÐÅÌß - óäîâëåòâîðÿåò óñëîâèþ");
RefreshRates();
for(try = 1; try <= 2; try++)
{
if (OrderSend(Symbol(),OP_SELL,Lots,Bid,10,0,0 ,"",Magic,0,Red) < 0)
{ Print("Îøèáêà ", ErrorDescription(GetLastError()));
Print("Íåâîçìîæíî îòêðûòü îðäåð, ïîïûòêà ", try);
Sleep(1000);
RefreshRates();
}
else
{
Tr = false;
SL = Bid;
Print(SL, "SL ÐÀÂÍÎ ÖÅÍÅ ÎÒÊÐÛÒÈß");
Print("Ïðîøëî âðåìåíè", TimeCurrent() - TimeSpeedDown, "ñåê");
OrderSal = true;
break;
}
}
}
}
else
{
Print("Ïàðàìåòð ââåðõ - óäîâëåòâîðÿåò óñëîâèþ");
if(TimeCurrent() - TimeSpeedUp <= timeSpeed)
{
Print("Ïàðàìåòð ÂÐÅÌß - óäîâëåòâîðÿåò óñëîâèþ");
RefreshRates();
for(try = 1; try <= 2; try++)
{
if (OrderSend(Symbol(),OP_BUY,Lots,Ask,10,0,0, "", Magic, 0, Green) < 0)
{ Print("Îøèáêà ", ErrorDescription(GetLastError()));
Print("Íåâîçìîæíî îòêðûòü îðäåð, ïîïûòêà ", try);
Sleep(1000);
RefreshRates();
}
else
{
Tr = false;
SL = Ask;
Print(SL, "SL ÐÀÂÍÎ ÖÅÍÅ ÎÒÊÐÛÒÈß");
Print("Ïðîøëî âðåìåíè", TimeCurrent() - TimeSpeedUp, "ñåê");
OrderSal = true;
break;
}
}
}
}
priceUp = 0;
priceDown = 0;
up = 0;
down = 0;
TimBoolUp = false;
TimBoolDown = false;
TimeSpeedUp = 0;
TimeSpeedDown = 0;
}
int init()
{
Magic = Get.Magic();
Point_= Point;
return(0);
}
int deinit()
{
return(0);
}
int start()
{
total = OrdersTotal();
int i, currentSymbolOrderPos = -1;
for (i = 0; i < total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
currentSymbolOrderPos = i;
break;
}
}
if (currentSymbolOrderPos < 0)
{
if(priceUp < Ask)
{
up = up + 1;
priceUp = Ask;
if(TimBoolUp == false)
{
TimeSpeedUp = TimeCurrent();
TimBoolUp = true;
}
}
else
{
priceUp = 0;
up = 0;
TimBoolUp = false;
TimeSpeedUp = 0;
}
if(priceDown > Ask)
{
down = down + 1;
priceDown = Ask;
if(TimBoolDown == false)
{
TimeSpeedDown = TimeCurrent();
TimBoolDown = true;
}
}
else
{
priceDown = 0;
down = 0;
TimBoolDown = false;
TimeSpeedDown = 0;
}
if(up == Speed || down == Speed)
{
openOrders();
}
if(priceUp == 0)
{
priceUp = Ask;
}
if(priceDown == 0)
{
priceDown = Ask;
}
}
else // Åñòü îòêðûòûé îðäåð ïî òåêóùåìó ñèìâîëó
{
OrderSelect(currentSymbolOrderPos, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY)
{
if(OrderSal == true)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid - StopLoss*Point,Digits),'', 0, Red);
OrderSal = false;
}
if (SL < Bid-(TrSt*Point))
{
if(OrderProfit() > 0)
{
Print("Óñëîâèå SL < Öåíà - Trst", SL ,">", Bid-(TrSt*Point));
SL = Bid-(TrSt*Point);
Tr = true;
}
}
if(Bid - OrderOpenPrice() <= -1 * StopLossReal * Point)
{
CloseOrder();
}
if(Tr == true && Bid <= SL)
{
CloseOrder();
}
}
if (OrderType() == OP_SELL)
{
if(OrderSal == true)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask + StopLoss*Point, Digits),'', 0, Red);
OrderSal = false;
}
if (SL > Ask +(TrSt*Point))
{
if(OrderProfit() > 0)
{
Print("Óñëîâèå SL > Öåíà + Trst", SL, ">", Ask +(TrSt*Point));
SL = Ask +(TrSt*Point);
Tr = true;
}
}
if(OrderOpenPrice()-Ask <= -1 * StopLossReal * Point)
{
CloseOrder();
}
if(Tr == true && Ask >= SL)
{
CloseOrder();
}
}
}
return(0);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---