Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
Profitability Reports
AUD/USD
Oct 2024 - Jan 2025
47.00 %
Total Trades
91
Won Trades
0
Lost trades
0
Win Rate
0.00 %
Expected payoff
-46.87
Gross Profit
3712.00
Gross Loss
-7977.00
Total Net Profit
-4265.00
-100%
-50%
0%
50%
100%
GBP/USD
Oct 2024 - Jan 2025
51.00 %
Total Trades
93
Won Trades
19
Lost trades
74
Win Rate
0.20 %
Expected payoff
-58.60
Gross Profit
5785.00
Gross Loss
-11235.00
Total Net Profit
-5450.00
-100%
-50%
0%
50%
100%
SMARTASS-Original
//---- Trades limits
extern double Lots = 1;
extern double TakeProfit = 1500;
extern double TrailingStop = 2000;
extern double StopLoss = 200;
extern int Slippage = 5;
extern double MaximumRisk = 0.3;
extern int StartTrading = 0;
extern int EndTrading = 24;
extern bool UseMM=false;
//--- Global variables
extern int MagicNumber = 655321;
string ExpertComment = "SMARTASS";
int NumberOfTries = 5;
//+------------------------------------------------------------------
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------
bool isNewSymbol(string current_symbol)
{
//loop through all the opened order and compare the symbols
int total = OrdersTotal();
for(int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
string selected_symbol = OrderSymbol();
if (current_symbol == selected_symbol && OrderMagicNumber()==MagicNumber)
return (False);
}
return (True);
}
//+------------------------------------------------------------------+
int start()
{
if (Hour()< StartTrading || Hour()>(EndTrading-1))
{
CloseOrder(OP_BUY);
CloseOrder(OP_SELL);
return(0);
}
int cnt, ticket, total,n,trend;
bool up1,up2,down1,down2,up3,down3;
bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ;
double signal,signal1,signal2;
if(Bars<50) {Print("bars less than 50"); return(0);}
//Symbo settings:
RefreshRates();
Slippage = MarketInfo(Symbol(),MODE_SPREAD);
double ma1=iMA(NULL,0,8,0,MODE_LWMA,PRICE_TYPICAL,1);
double ma2=iMA(NULL,0,21,0,MODE_LWMA,PRICE_TYPICAL,1);
double ma1last=iMA(NULL,0,8,0,MODE_LWMA,PRICE_TYPICAL,2);
double ma2last=iMA(NULL,0,21,0,MODE_LWMA,PRICE_TYPICAL,2);
double stoch_main = iStochastic(NULL,0,12,12,5,MODE_EMA,0,MODE_MAIN,1);
double stoch_sig = iStochastic(NULL,0,12,12,5,MODE_EMA,0,MODE_SIGNAL,1);
double stoch_main1 = iStochastic(NULL,0,12,12,5,MODE_EMA,0,MODE_MAIN,2);
double stoch_sig1 = iStochastic(NULL,0,12,12,5,MODE_EMA,0,MODE_SIGNAL,2);
double macd_main=iMACD(NULL,0,13,21,13,PRICE_WEIGHTED,MODE_MAIN,1);
double macd_sig=iMACD(NULL,0,13,21,13,PRICE_WEIGHTED,MODE_SIGNAL,1);
double macd_main1=iMACD(NULL,0,13,21,13,PRICE_WEIGHTED,MODE_MAIN,2);
double macd_sig1=iMACD(NULL,0,13,21,13,PRICE_WEIGHTED,MODE_SIGNAL,2);
double sar1=iSAR(NULL,0,0.0026,0.5,1);
double sar2=iSAR(NULL,0,0.0026,0.5,2);
if ((ma1>ma2 && stoch_main>stoch_sig && macd_main>macd_sig) && (sar1<Low[1])) up1=true; else up1=false;
if ((ma1<ma2 && stoch_main<stoch_sig && macd_main<macd_sig) && (sar1>High[1])) down1=true; else down1=false;
if ((ma1last>ma2last && stoch_main1>stoch_sig1 && macd_main1>macd_sig1) && (sar2<Low[2])) up2=true; else up2=false;
if ((ma1last<ma2last && stoch_main1<stoch_sig1 && macd_main1<macd_sig1) && (sar2>High[2])) down2=true; else down2=false;
static int arrow;
if ((up1==true && up2!=true))
{signal=1;}
else if ((down1==true && down2!=true))
{signal=-1;}
if ((up2==true && up1!=true)) CloseBuyCondition=true;
if (down2==true && down1!=true) CloseSellCondition=true;
//Print(signal);
//--- Trading conditions
/* bool BuyCondition = false , SellCondition = false , CloseBuyCondition = false , CloseSellCondition = false ; */
if (signal==1)
BuyCondition = true;
if (signal==-1)
SellCondition = true;
if (BuyCondition)
CloseSellCondition = true;
if (SellCondition)
CloseBuyCondition = true;
total = OrdersTotal();
if (UseMM)
Lots=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
if(total < 1 || isNewSymbol(Symbol()))
{
if(BuyCondition) //<-- BUY condition
{
ticket = OpenOrder(OP_BUY); //<-- Open BUY order
return(0);
}
if(SellCondition) //<-- SELL condition
{
ticket = OpenOrder(OP_SELL); //<-- Open SELL order
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) //<-- Long position is opened
{
if(CloseBuyCondition) //<-- Close the order and exit!
{
CloseOrder(OrderType());
}
TrailOrder(OrderType()); //<-- Trailling the order
}
if(OrderType()==OP_SELL) //<-- Go to short position
{
if(CloseSellCondition) //<-- Close the order and exit!
{
CloseOrder(OP_SELL);
}
TrailOrder(OrderType()); //<-- Trailling the order
}
}
}
return(0);
}
//+------------------------------------------------------------------+
int OpenOrder(int type)
{
int ticket=0;
int err=0;
int c = 0;
if(type==OP_BUY)
{
for(c = 0 ; c < NumberOfTries ; c++)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,ExpertComment,MagicNumber,0,Green);
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
break;
}
}
}
}
if(type==OP_SELL)
{
for(c = 0 ; c < NumberOfTries ; c++)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,ExpertComment,MagicNumber,0,Red);
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
break;
}
}
}
}
return(ticket);
}
bool CloseOrder(int type)
{
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
return (OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet));
if(type==OP_SELL)
return (OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet));
}
}
void TrailOrder(int type)
{
if(TrailingStop>0)
{
if(OrderMagicNumber() == MagicNumber)
{
if(type==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}
}
}
if(type==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}
}
}
}
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
---