|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hey-
Set an external double like: extern double RiskFraction=0.1; Then in the "start(" add: double Lots=(MathRound(AccountFreeMargin()*RiskFraction/10.0)/100); .... OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,"EA Name",MagicNum,0,Green); .1 means risk 10% of your account. Good luck ,Gavner |
|
||||
|
Question
Quote:
This is what i was looking for, for my EA. Also, is there a part of code which will limit how many trades will be opened based on the Avaliable Margin. Example: It will continue to open trades until 50% of the available Margin balance is used? Thanks! Spider~ Last edited by Spider4896 : 06-22-2006 at 01:11 AM. Reason: Adding response |
|
|||
|
Quote:
//+------------------------------------------------------------------+ //| Custom Moving Average.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //---- indicator parameters extern int ExtDepth=12; extern int ExtDeviation=5; extern int ExtBackstep=3; //---- indicator buffers double ExtMapBuffer[]; double ExtMapBuffer2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(2); //---- drawing settings SetIndexStyle(0,DRAW_SECTION); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer); SetIndexBuffer(1,ExtMapBuffer2); SetIndexEmptyValue(0,0.0); ArraySetAsSeries(ExtMapBuffer,true); ArraySetAsSeries(ExtMapBuffer2,true); //---- indicator short name IndicatorShortName("ZigZag("+ExtDepth+","+ExtDevia tion+","+ExtBackstep+")"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int shift, back,lasthighpos,lastlowpos; double val,res; double curlow,curhigh,lasthigh,lastlow; for(shift=Bars-ExtDepth; shift>=0; shift--) { val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)]; if(val==lastlow) val=0.0; else { lastlow=val; if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtMapBuffer[shift+back]; if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0; } } } ExtMapBuffer[shift]=val; //--- high val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-High[shift])>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtMapBuffer2[shift+back]; if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0; } } } ExtMapBuffer2[shift]=val; } // final cutting lasthigh=-1; lasthighpos=-1; lastlow=-1; lastlowpos=-1; for(shift=Bars-ExtDepth; shift>=0; shift--) { curlow=ExtMapBuffer[shift]; curhigh=ExtMapBuffer2[shift]; if((curlow==0)&&(curhigh==0)) continue; //--- if(curhigh!=0) { if(lasthigh>0) { if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0; else ExtMapBuffer2[shift]=0; } //--- if(lasthigh<curhigh || lasthigh<0) { lasthigh=curhigh; lasthighpos=shift; } lastlow=-1; } //---- if(curlow!=0) { if(lastlow>0) { if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0; else ExtMapBuffer[shift]=0; } //--- if((curlow<lastlow)||(lastlow<0)) { lastlow=curlow; lastlowpos=shift; } lasthigh=-1; } } for(shift=Bars-1; shift>=0; shift--) { if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0; else { res=ExtMapBuffer2[shift]; if(res!=0.0) ExtMapBuffer[shift]=res; } } } |
|
||||
|
Need Account triggered stop loss code..programmers wanted
I would like to use a stop loss that is triggered based on the account equity falling below the account balance by a specified percent. With one strategy something simple like ZERO percent should work
,but I'd like to be able to use this on other strategies too so I'd like to be able to specify a tolerance percentage of loss for each losing position this way. On triggering I would like it to close all open orders.Could someone make this for me. I have a strategy that would really benefit from this. Trouble is that a traditional stop loss messes it up. If I can get the losers stopped out so they don't draw down the equity from the winners it should really rock and roll. Last edited by Aaragorn : 06-25-2006 at 01:40 AM. |
|
||||
|
PHP Code:
Last edited by Aaragorn : 06-25-2006 at 03:42 AM. |
|
||||
|
upon closer inspection it appears that what I have IS working and behaving exactly like a stop loss.
when I add this to it... if(AccountEquity()+8<AccountBalance()) it behaves exactly like a stop loss at 8 so at least I've done the code right for once eh? Sadlly it's not producing the effect I wanted in the EA. It's messing with the winners who need the stop loss wider to work too. victory and defeat all at the same time...ok so be it. |
|
||||
|
Code debugging issue...trailing stop trigger..coders wanted
PHP Code:
I'm wondering if this is written correctly as 'Point*TrailingStopTrigger' is it supposed to multiply or simply add the value of the TrailingStopTrigger to Point for sell positions and subtract if for buy positions. Is that why it's not triggering like it's supposed to? Or is there something else? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to code this? | iscuba11 | Metatrader 4 mql 4 - Development course | 1 | 08-03-2007 04:22 PM |