Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


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

Reply
 
LinkBack Thread Tools Display Modes
  #111 (permalink)  
Old 06-16-2006, 04:12 AM
goover goover is offline
Member
 
Join Date: Feb 2006
Posts: 43
goover is on a distinguished road
Hi Maji,

Thanks for the confirmation and the offset comment. Now i know how to use the offset.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #112 (permalink)  
Old 06-17-2006, 04:37 AM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
lot scaling question ..need code help..

I know that I am responsible for taking my own risks when using any strategy. I don't want to scare anyone. I'm looking for some help with a code that I could put in an EA which would adjust the lot size of orders according to a percentage of the current free margin in the account and let me choose what percentage of that to enter the next position with.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #113 (permalink)  
Old 06-20-2006, 04:06 AM
Gavner Gavner is offline
Junior Member
 
Join Date: Apr 2006
Location: Boston
Posts: 8
Gavner is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #114 (permalink)  
Old 06-21-2006, 05:28 PM
Spider4896's Avatar
Spider4896 Spider4896 is offline
Member
 
Join Date: Apr 2006
Posts: 69
Spider4896 is on a distinguished road
Question

Quote:
Originally Posted by Gavner
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

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #115 (permalink)  
Old 06-22-2006, 07:13 PM
viktoriwan viktoriwan is offline
Junior Member
 
Join Date: May 2006
Posts: 21
viktoriwan is on a distinguished road
Need Coders to Break The Code

Quote:
Originally Posted by viktoriwan
it goes something like this :
if(mov(zig(4,c),4,e) - mov(zig(9,c),7,e)
Hello... anyone notice this thread and want to help me ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #116 (permalink)  
Old 06-22-2006, 07:58 PM
rbowles rbowles is offline
Junior Member
 
Join Date: Jun 2006
Posts: 15
rbowles is on a distinguished road
Quote:
Originally Posted by viktoriwan
Hello... anyone notice this thread and want to help me ?
Mine has the zigzag formula built in. I am not sure if that is what you want but here it is.

//+------------------------------------------------------------------+
//| 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;
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #117 (permalink)  
Old 06-25-2006, 01:35 AM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #118 (permalink)  
Old 06-25-2006, 02:14 AM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
PHP Code:
if(AccountEquity()<AccountBalance()) { 
{
  
int ttotal OrdersTotal();
  for(
int i=ttotal-1;i>=0;i--)
  {
    
OrderSelect(iSELECT_BY_POS);
    
int type   OrderType();

    
bool result false;
    
    switch(
type)
    {
      
//Close opened long positions
      
case OP_BUY       result OrderCloseOrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5Red );
                          break;
      
      
//Close opened short positions
      
case OP_SELL      result OrderCloseOrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5Red );
                          
    }
    
    if(
result == false)
    {
      
Alert("Order " OrderTicket() , " failed to close. Error:" GetLastError() );
      
Sleep(3000);
    }  
  }
  
  return(
0);
}
}

ok this is what I tried ..it's mostly copied from another code someone else here made...but it's just closing everything as fast as they open and not paying any attention to the 'if' condition before executing closes....oy I'm not good at this....I obviously don't have the part that is doing the closing of orders sufficiently attached to the conditional line that compares the account equity to the account balance. Could someone please help me with this?

Last edited by Aaragorn : 06-25-2006 at 03:42 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #119 (permalink)  
Old 06-25-2006, 05:35 AM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #120 (permalink)  
Old 06-25-2006, 10:16 PM
Aaragorn's Avatar
Aaragorn Aaragorn is offline
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
Code debugging issue...trailing stop trigger..coders wanted

PHP Code:
for(cnt=0;cnt<total;cnt++) {
OrderSelect(cntSELECT_BY_POSMODE_TRADES);
if(
OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {
if(
OrderType()==OP_BUY){
if(
TrailingStop>0) {
if(
Bid-OrderOpenPrice()>Point*TrailingStopTrigger) {
if(
OrderStopLoss()<Bid-Point*TrailingStop) {
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(
0);
}
}
}
}else{
if(
TrailingStop>0) {
if((
OrderOpenPrice()-Ask)>(Point*TrailingStopTrigger)) {
if((
OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(
0); 
I'm still learning code. This is supposed to trigger a trailing stop to engage as a specified level. I can see from some test results that it didn't trigger when it should have.

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


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


All times are GMT. The time now is 10:40 PM.