Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
Profitability Reports
AUD/USD
Oct 2024 - Jan 2025
0.00 %
Total Trades
10
Won Trades
0
Lost trades
0
Win Rate
0.00 %
Expected payoff
-246.80
Gross Profit
0.00
Gross Loss
-2468.00
Total Net Profit
-2468.00
-100%
-50%
0%
50%
100%
GBP/USD
Oct 2024 - Jan 2025
0.00 %
Total Trades
4
Won Trades
3
Lost trades
1
Win Rate
0.75 %
Expected payoff
-777.50
Gross Profit
0.00
Gross Loss
-3110.00
Total Net Profit
-3110.00
-100%
-50%
0%
50%
100%
Samuray_v3
//+------------------------------------------------------------------+
//| Samuray.mq4 |
//| Kokas |
//| http://www.forexforums.org |
//+------------------------------------------------------------------+
#property copyright "Kokas"
#property link "http://www.forexforums.org"
//---- input parameters
extern string ExpertName = "Samuray V.3 GBPJPY";
extern bool AutoTrade = true;
extern int MaxTrades = 50;
extern double RecycleProfit = 500;
extern bool UseSwap = false;
extern double InitialStop = 0; //
extern double BreakEven = 20; // Profit Lock in pips
extern double StepSize = 10; // distance to move SL
extern double MinDistance = 15;
extern bool SecureOrders = true; // If set to true only open orders when in profit MinPip
extern double MinPip = 20; // Min Profit Pips to open another order (read above)
extern bool CloseAll = false; // Set true to close all current Orders
extern int Magic = 5665; // Magic Number of the EA
extern double Lots = 0.1; // Lot size when not using MM
extern bool MoneyManagement = true; // Set to true to use Money Management
extern double MaxLotSize = 100; // Max Lot size when using Money Management
extern double Risk = 10; // Risk factor when using MM
extern bool UseBollinger = false; // Turn to true to filter your orders with Bollinger Bands
extern string Param2 = "Bollinger Band Settings";
extern double Bollinger_Period = 20;
extern double Bollinger_TF = 60;
extern double Bollinger_Dev = 2;
extern bool UseEmaFilter = true; // Turn true to filter orders using EMA's
extern int ShortEma = 20;
extern int LongEma = 100;
int k, digit=0;
bool BE = false;
double AccountSize,totalPips,totalProfits,SEma,LEma,error;
double pBid, pAsk, pp,valueswap;
bool AccountIsMicro;
bool signal1 = true, signal2 =true, signal3 = true , signal4 = true, signal5 = true, SecureSignal = true;
string comment = "";
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if (MarketInfo(Symbol(),MODE_LOTSTEP) == 0.01)
{
AccountIsMicro = true;
}
else
{
AccountIsMicro = false;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
void ChartComment()
{
string sComment = "";
string sp = "****************************\n";
string NL = "\n";
sComment = sp;
sComment = sComment + "Open Positions = " + ScanOpenTrades() + NL;
sComment = sComment + "Current Profit(Pip)= " + totalPips + NL;
sComment = sComment + "SWAP Value (Pip) = " + DoubleToStr(valueswap,2) + NL;
if(UseSwap){
sComment = sComment + "SWAP Enabled" + NL;
} else {
sComment = sComment + "SWAP Disabled" + NL;
}
sComment = NL + sComment + "Net Value (Pip) = " + DoubleToStr(totalPips+valueswap,2) + NL;
sComment = sComment + NL + sp;
Comment(sComment);
}
int ScanOpenTrades()
{
int total = OrdersTotal();
int numords = 0;
for(int cnt=0; cnt<=total-1; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if(OrderType()<=OP_SELL)
{
if(Magic > 0) if(OrderMagicNumber() == Magic) numords++;
if(Magic == 0) numords++;
}
}
return(numords);
}
// Closing of Open Orders
void OpenOrdClose()
{
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
bool res = false;
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition && ( mode==OP_BUY || mode==OP_SELL ))
{
// - BUY Orders
if(mode==OP_BUY)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Yellow);
if( !res )
{
Print(" BUY: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
break;
}
else
// - SELL Orders
if( mode == OP_SELL)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,White);
if( !res )
{
Print(" SELL: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
break;
}
}
}
}
void TotalProfit()
{
int total=OrdersTotal();
totalPips = 0;
totalProfits = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((Bid-OrderOpenPrice())/Point);
totalProfits += OrderProfit();
break;
case OP_SELL:
totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((OrderOpenPrice()-Ask)/Point);
totalProfits += OrderProfit();
break;
}
}
if (UseSwap) {
SwapProfit();
totalProfits = totalProfits + valueswap;
}
}
}
// MoneyManagement with Account Leverage Protection
double LotSize()
{
double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / AccountLeverage() / 2;
if(AccountIsMicro==false) //normal account
{
if(lotMM < 0.1) lotMM = 0.1;
if((lotMM >= 0.1) && (lotMM < 0.2)) lotMM = 0.2;
if((lotMM >= 0.2) && (lotMM < 0.3)) lotMM = 0.3;
if((lotMM >= 0.3) && (lotMM < 0.4)) lotMM = 0.4;
if((lotMM >= 0.4) && (lotMM < 1)) lotMM = 0.5;
if(lotMM >= 1.0) lotMM = MathCeil(lotMM);
if(lotMM >= MaxLotSize) lotMM = MaxLotSize;
}
else //micro account
{
if(lotMM < 0.01) lotMM = 0.01;
if((lotMM >= 0.01) && (lotMM < 0.02)) lotMM = 0.02;
if((lotMM >= 0.02) && (lotMM < 0.03)) lotMM = 0.03;
if((lotMM >= 0.03) && (lotMM < 0.04)) lotMM = 0.04;
if((lotMM >= 0.05) && (lotMM < 0.06)) lotMM = 0.05;
if((lotMM >= 0.06) && (lotMM < 0.07)) lotMM = 0.06;
if((lotMM >= 0.07) && (lotMM < 0.08)) lotMM = 0.08;
if((lotMM >= 0.08) && (lotMM < 0.09)) lotMM = 0.09;
if((lotMM >= 0.09) && (lotMM < 0.10)) lotMM = 0.1;
if((lotMM >= 0.1) && (lotMM < 0.2)) lotMM = 0.2;
if((lotMM >= 0.2) && (lotMM < 0.3)) lotMM = 0.3;
if((lotMM >= 0.3) && (lotMM < 0.4)) lotMM = 0.4;
if((lotMM >= 0.4) && (lotMM < 1)) lotMM = 0.5;
if(lotMM >= 1.0) lotMM = MathCeil(lotMM);
if(lotMM >= MaxLotSize) lotMM = MaxLotSize;
}
if(AccountIsMicro) {
AccountSize=2;
} else {
AccountSize=1;
}
lotMM = NormalizeDouble(lotMM,AccountSize);
return (lotMM);
}
void StepStops()
{
double BuyStop, SellStop;
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic )
{
if ( mode==OP_BUY )
{
BuyStop = OrderStopLoss();
if ( Bid-OrderOpenPrice()>0 || OrderStopLoss()==0)
{
if ( Bid-OrderOpenPrice()>=Point*BreakEven && !BE) {BuyStop = OrderOpenPrice();BE = true;}
if (OrderStopLoss()==0) {BuyStop = OrderOpenPrice() - InitialStop * Point; k=1; BE = false;}
if ( Bid-OrderOpenPrice()>= k*StepSize*Point)
{
BuyStop = OrderStopLoss()+ StepSize*Point;
if (Bid - BuyStop >= MinDistance*Point)
{ BuyStop = BuyStop; k=k+1;}
else
BuyStop = OrderStopLoss();
}
//Print( " k=",k ," del=", k*StepSize*Point, " BuyStop=", BuyStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(BuyStop, digit),
OrderTakeProfit(),0,LightGreen);
return(0);
}
}
if ( mode==OP_SELL )
{
SellStop = OrderStopLoss();
if ( OrderOpenPrice()-Ask>0 || OrderStopLoss()==0)
{
if ( OrderOpenPrice()-Ask>=Point*BreakEven && !BE) {SellStop = OrderOpenPrice(); BE = true;}
if ( OrderStopLoss()==0 ) { SellStop = OrderOpenPrice() + InitialStop * Point; k=1; BE = false;}
if ( OrderOpenPrice()-Ask>=k*StepSize*Point)
{
SellStop = OrderStopLoss() - StepSize*Point;
if (SellStop - Ask >= MinDistance*Point)
{ SellStop = SellStop; k=k+1;}
else
SellStop = OrderStopLoss();
}
//Print( " k=",k," del=", k*StepSize*Point, " SellStop=",SellStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(SellStop, digit),
OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}
void SwapProfit()
{
int total=OrdersTotal();
valueswap = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition && OrderSwap()!=0)
{
valueswap = valueswap + OrderSwap()/PipCost(OrderSymbol()); // ERROOOOOOOOOOOOOOOOOOOOOOOOOOO
}
}
}
//+--------- --------- --------- --------- --------- --------- ----+
//+ Calculate cost in USD of 1pip of given symbol
//+--------- --------- --------- --------- --------- --------- ----+
double PipCost (string TradeSymbol) {
double Base, Cost;
string TS_13, TS_46, TS_4L;
TS_13 = StringSubstr (TradeSymbol, 0, 3);
TS_46 = StringSubstr (TradeSymbol, 3, 3);
TS_4L = StringSubstr (TradeSymbol, 3, StringLen(TradeSymbol)-3);
Base = MarketInfo (TradeSymbol, MODE_LOTSIZE) * MarketInfo (TradeSymbol,MODE_POINT);
if ( TS_46 == "USD" )
Cost = Base;
else if ( TS_13 == "USD" )
Cost = Base / MarketInfo (TradeSymbol, MODE_BID);
else if ( PairExists ("USD"+TS_4L) )
Cost = Base / MarketInfo ("USD"+TS_4L, MODE_BID);
else
Cost = Base * MarketInfo (TS_46+"USD" , MODE_BID);
return(Cost) ;
}
//+--------- --------- --------- --------- --------- --------- ----+
//+ Returns true if given symbol exists
//+--------- --------- --------- --------- --------- --------- ----+
bool PairExists (string TradeSymbol) {
return ( MarketInfo (TradeSymbol, MODE_LOTSIZE) > 0 );
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
digit = MarketInfo(Symbol(),MODE_DIGITS);
SEma = iMA(Symbol(),0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
LEma = iMA(Symbol(),0,LongEma,0,MODE_EMA,PRICE_CLOSE,0);
double BandsLower = iBands(Symbol(),Bollinger_TF,Bollinger_Period,Bollinger_Dev,0,0,2,0); // Lower Bollinger
double BandsUpper = iBands(Symbol(),Bollinger_TF,Bollinger_Period,Bollinger_Dev,0,0,1,0); // Upper Bollinger
double Bands = (BandsLower + BandsUpper) / 2; // Middle Bollinger
signal1 = false;
signal2 = false;
signal3 = true;
signal4 = true;
if (CloseAll) {
OpenOrdClose();
signal4 = false;
}
TotalProfit();
if (totalPips > RecycleProfit) {
OpenOrdClose();
signal4 = false;
}
if (ScanOpenTrades() < MaxTrades) signal1 = true;
if (ScanOpenTrades() == 0){
signal2 = true;
} else {
signal2 = true; // if (AccountFreeMargin() > (AccountBalance()+AccountBalance()*MarginTrade/100)) signal2 = true; /// ERROOOOOOOOOOOOOOOOOOOOOOOOOOO
}
signal3 = true;
if (UseBollinger){
if (MarketInfo(Symbol(),MODE_ASK) < Bands) {
signal3 = true;
}else{
signal3 = false;
}
}
if (MoneyManagement) Lots = LotSize();
if (SecureOrders){
if (totalPips > MinPip || ScanOpenTrades() == 0){
SecureSignal = true;
} else {
SecureSignal = false;
}
} else {
SecureSignal = true;
}
if ((SEma > LEma) && (SEma != LEma)){
signal5 = true;
} else {
signal5 = false;
}
comment = "Samuray:" + DoubleToStr(ScanOpenTrades() + 1,0);
//+------------------------------------------------------------------+
if (!signal1) Print("Max trades Reached");
if (!signal2) Print("Not enougth Margin");
if (!signal3) Print("Bollinger does not allow");
if (!signal4) Print("Recycling Orders");
if (!signal5) Print("Ask EMA to enter trades!");
if (!AutoTrade) Print("Autotrade disabled on properties");
if (!SecureSignal) Print("Not safe to enter yet");
if (signal1 && signal2 && signal3 && signal4 && signal5 && AutoTrade && SecureSignal){
// signal1 - Control the number of open orders
// signal2 - Check Margin (INACTIVE)
// signal3 - Bollinger Bands Filter
// signal4 - Control Recycle Profits
// signal5 - Check EMA's before place trades
error = 1;
while (error != 0) {
OrderSend(Symbol(),OP_BUY,Lots,MarketInfo(Symbol(),MODE_ASK),3,0,0,comment,Magic,0,Blue);
error = GetLastError();
if (error !=0 ) Print(error);
}
}
if (BreakEven>0 || InitialStop>0 || StepSize>0) StepStops();
ChartComment();
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
---