Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
Swetten
//+------------------------------------------------------------------+
//| Swetten |
//|Èñõîäíèê ýòîãî ñîâåòíèêà óòåðÿí, íî, ïî ìîåìó, àâòîð Klot. |
//|Ïîìîãàëè ñîâåòàìè çäåñü: http://forum.mql4.com/ru/15200 |
//+------------------------------------------------------------------+
#property copyright "Swetten"
#property link ""
#include <stdlib.mqh>
#import "NS2-32.dll"
int OpenNet(string defpath, int& netnumber[1], int& Nin[1], int& Nout[1]); // Îòêðûòèå ñåòè
int FireNet(int& netnumber[1], double& inarray[], double& outarray[]); // Âûïîëíåíèå ñåòè
int CloseNet(int& netnumber[1]); // Çàêðûòèå ñåòè
#import
int ret;
int Stop;
int Error;
int Nin[1]; // Ðàçìåð ìàññèâà âõîäîâ
int Nout[1]; // Ðàçìåð ìàññèâà âûõîäîâ
int netnumber[1]; // Óêàçàòåëü íà ñåòü
int LotsWayChoice = 0;
int BuyTicket = 0;
int SellTicket = 0;
int Takeprofit = 154;
int StopLoss;
int OpenTrade;
int TimeFrame;
int TakeProfit;
int ChannelPeriod;
int CloseTrade;
int SlipPage=3;
int LotsPercent;
int MagicNumber;
// Òóò çàäàåòñÿ ïóòü è èìÿ ôàéëà íåéðîñåòè
string BuyComment = "", SellComment = "";
string defpath="C:\EURUSD.def";
double Lots;
double kanal = 0 ;
double inarray[], outarray[];
double BuySwap = 0.0, SellSwap = 0.0;
double BuyLots = 0.0, SellLots = 0.0;
double BuyProfit = 0.0, SellProfit = 0.0;
double BuyStopLoss = 0.0, SellStopLoss = 0.0;
double BuyOpenPrice = 0.0, SellOpenPrice = 0.0;
double BuyTakeProfit = 0.0, SellTakeProfit = 0.0;
double BuyCommission = 0.0, SellCommission = 0.0;
datetime BuyOpenTime = -1, SellOpenTime = -1;
bool SIGNAL_BUY;
bool SIGNAL_SELL;
int init()
{
IdentificationÑurrencies();
ret=OpenNet(defpath, netnumber, Nin, Nout);
if (ret==0)
{
Print("netnumber= ",netnumber[0], " Nin= ",Nin[0], " Nout= ",Nout[0]);
ArrayResize(inarray,Nin[0]);
ArrayResize(outarray,Nout[0]);
}
else
{
Print( "Îøèáêà OpenNet ", ret );
return(0);
}
return(0);
}
int deinit()
{
ret=CloseNet(netnumber); // Çàêðûâàåì ñåòü
if ( ret!=0 ) Print( "Îøèáêà CloseNet ", ret );
return(0);
}
int start()
{
OneTypeOrdersInit( MagicNumber );
ConditionsSignal();
CloseOrders();
OpenOrders();
return(0);
}
void IdentificationÑurrencies()
{
TakeProfit =150;
StopLoss =40;
Lots = 0.1;
return;
}
int ConditionsSignal ()
{
if( DayOfWeek() == 0 || DayOfWeek() == 6 ) return(0);
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
bool T = (
( Hour()== 0 && Minute()==0 ) ||
( Hour()== 2 && Minute()==0 ) ||
( Hour()== 4 && Minute()==0 ) ||
( Hour()== 6 && Minute()==0 ) ||
( Hour()== 8 && Minute()==0 ) ||
( Hour()== 10 && Minute()==0 ) ||
( Hour()== 12 && Minute()==0 ) ||
( Hour()== 14 && Minute()==0 ) ||
( Hour()== 16 && Minute()==0 ) ||
( Hour()== 18 && Minute()==0 ) ||
( Hour()== 20 && Minute()==0 ) ||
( Hour()== 22 && Minute()==0 )
) ;
if (T == 0) return(0);
SIGNAL_BUY = false;
SIGNAL_SELL = false;
int i = 1;
inarray[0]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,144,0, MODE_SMA,0,1);
inarray[1]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,89,0, MODE_SMA,0,1);
inarray[2]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,55,0, MODE_SMA,0,1);
inarray[3]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,34,0, MODE_SMA,0,1);
inarray[4]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,21,0, MODE_SMA,0,1);
inarray[5]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,13,0, MODE_SMA,0,1);
inarray[6]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,8,0, MODE_SMA,0,1);
inarray[7]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,5,0, MODE_SMA,0,1);
inarray[8]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,3,0, MODE_SMA,0,1);
inarray[9]=iMA(NULL, PERIOD_M1,233,0, MODE_SMA,0,1)-iMA(NULL, PERIOD_M1,2,0, MODE_SMA,0,1);
FireNet(netnumber, inarray, outarray);
Print(outarray[0]);
if (outarray[0] > 0) SIGNAL_BUY = true ;
if (outarray[0] < 0) SIGNAL_SELL = true ;
return(0);
}
//+------------------------------------------------------------------+
int OpenOrders()
{
if ( SellTicket>0 || BuyTicket >0 ) return(0);
if (SIGNAL_BUY )
{
BuyOpenPrice = NormalizeDouble( Ask , Digits );
if ( OrderSend( Symbol(), OP_BUY, LotsOptimized(), BuyOpenPrice,SlipPage, BuyOpenPrice - StopLoss*Point,BuyOpenPrice + TakeProfit*Point, "GOLDsuperVEIN", MagicNumber, 0, Blue ) < 0 )
{
Error = GetLastError();
Print( "Îøèáêà OrderSend ¹ ", Error );
return(-1);
}
return(0);
}
if (SIGNAL_SELL )
{
SellOpenPrice = NormalizeDouble( Bid , Digits );
if ( OrderSend( Symbol(), OP_SELL, LotsOptimized(), SellOpenPrice,SlipPage, SellOpenPrice + StopLoss*Point,SellOpenPrice - TakeProfit*Point, "GOLDsuperVEIN", MagicNumber, 0, Red ) < 0 )
{
Error = GetLastError();
Print( "Îøèáêà OrderSend ¹ ", Error );
return(-1);
}
return(0);
}
return(0);
}
//+------------------------------------------------------------------+
int CloseOrders()
{
if ( BuyTicket > 0 )
{
if (NormalizeDouble(Bid - Takeprofit*Point, Digits )>= BuyOpenPrice || SIGNAL_SELL )
{
if ( !OrderClose( BuyTicket, BuyLots, Bid, SlipPage, Aqua ) )
{
Error = GetLastError();
Print( "Îøèáêà OrderClose ¹ ", Error );
return(-1);
}
return(0);
}
}
if ( SellTicket > 0 )
{
if (NormalizeDouble(Ask + Takeprofit*Point, Digits )<= SellOpenPrice || SIGNAL_BUY )
{
if ( !OrderClose( SellTicket, SellLots, Ask, SlipPage, DeepPink ) )
{
Error = GetLastError();
Print( "Îøèáêà OrderClose ¹ ", Error );
return(-1);
}
return(0);
}
}
return(0);
}
//+------------------------------------------------------------------+
double LotsOptimized()
{
double dLot;
return(1);
}
//+------------------------------------------------------------------+
void OneTypeOrdersInit( int magic )
{
// îáíóëåíèå ïåðåìåííûõ:
BuyTicket = 0; SellTicket = 0;
BuyLots = 0.0; SellLots = 0.0;
BuyOpenPrice = 0.0; SellOpenPrice = 0.0;
BuyStopLoss = 0.0; SellStopLoss = 0.0;
BuyTakeProfit = 0.0; SellTakeProfit = 0.0;
BuyOpenTime = -1; SellOpenTime = -1;
BuyProfit = 0.0; SellProfit = 0.0; BuySwap = 0.0; SellSwap = 0.0;
BuyCommission = 0.0; SellCommission = 0.0;
BuyComment = ""; SellComment = "";
int Error = 0, Total = OrdersTotal();
for ( int i = Total - 1; i >= 0; i -- )
{
if ( !OrderSelect( i, SELECT_BY_POS ) )
{
Error = GetLastError();
Print( "OrderSelect( ", i, ", SELECT_BY_POS ) - Error #", Error );
continue;
}
if ( OrderMagicNumber() == magic && OrderSymbol() == Symbol() )
{
switch ( OrderType() )
{
case OP_BUY:
BuyTicket = OrderTicket();
BuyLots = NormalizeDouble( OrderLots(), 0.1 );
BuyOpenPrice = NormalizeDouble( OrderOpenPrice(), Digits );
BuyStopLoss = NormalizeDouble( OrderStopLoss(), Digits );
BuyTakeProfit = NormalizeDouble( OrderTakeProfit(), Digits );
BuyOpenTime = OrderOpenTime();
BuyProfit = NormalizeDouble( OrderProfit(), 2 );
BuySwap = NormalizeDouble( OrderSwap(), 2 );
BuyCommission = NormalizeDouble( OrderCommission(), 2 );
BuyComment = OrderComment();
break;
case OP_SELL:
SellTicket = OrderTicket();
SellLots = NormalizeDouble( OrderLots(), 0.1 );
SellOpenPrice = NormalizeDouble( OrderOpenPrice(), Digits );
SellStopLoss = NormalizeDouble( OrderStopLoss(), Digits );
SellTakeProfit = NormalizeDouble( OrderTakeProfit(), Digits );
SellOpenTime = OrderOpenTime();
SellProfit = NormalizeDouble( OrderProfit(), 2 );
SellSwap = NormalizeDouble( OrderSwap(), 2 );
SellCommission = NormalizeDouble( OrderCommission(), 2 );
SellComment = OrderComment();
break;
}
}
}
}
//+------------------------------------------------------------------+
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
---