Price Data Components
Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
VSA┬®
//+------------------------------------------------------------------+
//| VSA©FOREXflash.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, TradingSytemForex"
#property link "http://www.tradingsystemforex.com"
//+It has 4 states.
//+I believe that a price volume bar can have one of 4 states.
//+1. It can have increasing spread and decreasing volume. This means that price is
//moving without strong participation and can not be sustained. Due to the lack of participation,
//the price is ripe for a reversal. This is displayed as a Magenta Diamond on that bar.
//+2. It can have increasing spread and increasing volume. This means there is wide
//participation and price should continue in this direction.
//+A red arrow shows the direction down when supply is overtaking demand.
//+A blue arrow shows direction up when demand is overtaking supply.
//+3. It can have decreasing spread and increasing volume, which means that the supply
//and the demand are temporarily stalemated. This is a warning that the direction move
//may be losing steam.This is shown by a yellow x on that bar.
//+4. It can have decreasing spread and decreasing volume.
//This to me means that the bar has little participation from anyone and that the market
//is dull or congested. I do not show any indicator for this, because it does not portend
//any information other than dullness.
#define EAName "VSA©, FOREXflash"
extern string S2="---------------- Money Management";
extern double Lots=0.1;//|-----------------------lots size
extern bool RiskMM=false;//|---------------------risk management
extern double RiskPercent=1;//|------------------risk percentage
extern string S3="---------------- Order Management";
extern int StopLoss=0;//|------------------------stop loss
extern int TakeProfit=0;//|----------------------take profit
extern bool HideSL=false;//|---------------------hide stop loss
extern bool HideTP=false;//|---------------------hide take profit
extern int TrailingStop=0;//|--------------------trailing stop
extern int TrailingStep=0;//|--------------------trailing step
extern int BreakEven=0;//|-----------------------break even
extern int MaxOrders=1;//|---------------------maximum orders allowed
extern int Slippage=3;//|------------------------slippage
extern int Magic=2009;//|------------------------magic number
extern string S4="---------------- MA Filter";
extern bool MAFilter=true;//|-------------------moving average filter
extern int MAPeriod=5;//|-----------------------ma filter period
extern int MAMethod=0;//|------------------------ma filter method
extern int MAPrice=0;//|-------------------------ma filter price
extern string S5="---------------- Time Filter";
extern bool TradeOnSunday=true;//|---------------time filter on sunday
extern bool MondayToThursdayTimeFilter=false;//|-time filter the week
extern int MondayToThursdayStartHour=0;//|-------start hour time filter the week
extern int MondayToThursdayEndHour=24;//|--------end hour time filter the week
extern bool FridayTimeFilter=false;//|-----------time filter on friday
extern int FridayStartHour=0;//|-----------------start hour time filter on friday
extern int FridayEndHour=21;//|------------------end hour time filter on friday
extern string S6="---------------- Extras";
extern bool Hedge=false;//|----------------------enter an opposite trade
extern int Expiration=240;//|--------------------expiration in minute for the reverse pending order
extern bool Comments=true;//|--------------------allow comments on chart
datetime PreviousBarTime1;
datetime PreviousBarTime2;
double R[],D[],S[],W[];
double maxEquity,minEquity,Balance=0.0;
//|---------initialization
int init()
{
if(Comments)Comment("\nLoading...");
return(0);
}
//|---------deinitialization
int deinit()
{
ObjectsDeleteAll(0,OBJ_LABEL);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int VSA()
{
string VSACLOSE="false";
string VSABUY="false";
string VSASELL="false";
double spd1,spd2,v1,v2;
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=50; //Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
spd1 = High[i+1] - Low[i+1];
spd2 = High[i+2] - Low[i+2];
R[i]=0; D[i]=0; S[i]=0; W[i]=0;
v1=iVolume(NULL,0,i+1);
v2=iVolume(NULL,0,i+2);
if ( spd1 > spd2 )
{
if ( v1 < v2 )
{
if ( High[i+1]-Close[i+1] < Close[i+1]-Low[i+1] )
{
Comment("SIGNAL: Reversal");VSACLOSE="true";
}
if ( High[i+1]-Close[i+1] > Close[i+1]-Low[i+1] )
{
Comment("SIGNAL: Reversal");VSACLOSE="true";
}
}
if ( v1 > v2 )
{
if ( High[i+1]-Close[i+1] < Close[i+1]-Low[i+1] )
{
Comment("SIGNAL: Demand");VSABUY="true";
}
if ( High[i+1]-Close[i+1] > Close[i+1]-Low[i+1] )
{
Comment("SIGNAL: Supply");VSASELL="true";
}
}
}
if ( spd1 < spd2 )
if ( v1 > v2 )
{
Comment("SIGNAL: Warning");VSACLOSE="true";
}
if(VSABUY=="true") return(-1);
if(VSASELL=="true") return(1);
if(VSACLOSE=="true") return(2);
}
return(0);
}
//+------------------------------------------------------------------+
int start()
{
VSA();
CloseOrders();
//|---------trailing stop
if(TrailingStop>0)MoveTrailingStop();
//|---------break even
if(BreakEven>0)MoveBreakEven();
//|---------time filter
if((TradeOnSunday==false&&DayOfWeek()==0)||(MondayToThursdayTimeFilter&&DayOfWeek()>=1&&DayOfWeek()<=4&&!(Hour()>=MondayToThursdayStartHour&&Hour()<=MondayToThursdayEndHour))||(FridayTimeFilter&&DayOfWeek()==5&&!(Hour()>=FridayStartHour&&Hour()<=FridayEndHour)))
{
return(0);
}
//|---------risk management
if(RiskMM)CalculateMM();
//|---------open orders
double SL,TP,SLP,TPP,OPP;
int Ticket,TicketH,TicketP,Expire=0;
if(Expiration>0)Expire=TimeCurrent()+(Expiration*60)-5;
if(OrdersTotal()<MaxOrders)
{
if (VSA()==1 && iMomentum(Symbol(), 0,14,1, 0)>100&& NewBarBuy())
{
if(HideSL==false&&StopLoss>0){SL=Ask-StopLoss*Point;}else {SL=0;}
if(SL>0&&SL>(Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
if(HideTP==false&&TakeProfit>0){TP=Ask+TakeProfit*Point;}else {TP=0;}
Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,EAName,Magic,0,Blue);
}
if (VSA()==-1 && iMomentum(Symbol(), 0,14,1, 0)<100&& NewBarSell())
{
if(HideSL==false&&StopLoss>0){SL=Bid+StopLoss*Point;}else {SL=0;}
if(SL>0&&SL<(Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
if(HideTP==false&&TakeProfit>0){TP=Bid-TakeProfit*Point;}else {TP=0;}
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,EAName,Magic,0,Red);
}
}
//|---------not enough money warning
int err=0;
if(Ticket<0)
{
if(GetLastError()==134)
{
err=1;
Print("Not enough money!");
}
return (-1);
}
return(0);
}
//|---------close orders
int CloseOrders()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderType() == OP_BUY && VSA()==2)
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
if (OrderType() == OP_SELL && VSA()==2)
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
}
}
return;
}
//|---------trailing stop
void MoveTrailingStop()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
else
{
if(TrailingStop>0)
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
//|---------break even
void MoveBreakEven()
{
int cnt,total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(BreakEven>0)
{
if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
else
{
if(BreakEven>0)
{
if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point)
{
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}
//|---------allow one action per bar
bool NewBarBuy()
{
if(PreviousBarTime1<Time[0])
{
PreviousBarTime1=Time[0];
return(true);
}
return(false);
}
bool NewBarSell()
{
if(PreviousBarTime2<Time[0])
{
PreviousBarTime2=Time[0];
return(true);
}
return(false);
}
//|---------calculate money management
void CalculateMM()
{
double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
Lots=AccountFreeMargin()/100000*RiskPercent;
Lots=MathMin(MaxLots,MathMax(MinLots,Lots));
if(MinLots<0.1)Lots=NormalizeDouble(Lots,2);
else
{
if(MinLots<1)Lots=NormalizeDouble(Lots,1);
else Lots=NormalizeDouble(Lots,0);
}
if(Lots<MinLots)Lots=MinLots;
if(Lots>MaxLots)Lots=MaxLots;
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
---