الشعر و الشعراء / Poetry & Poets قسم خاص لكتابة الاشعار... وبوح المشاعر ..

إضافة رد
 
LinkBack أدوات الموضوع انواع عرض الموضوع
  #1  
قديم 11-17-2010, 01:20 AM
RSS RSS غير متواجد حالياً

ViP

 
تاريخ التسجيل: Mar 2010
المشاركات: 17,040
معدل تقييم المستوى: 67
RSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud ofRSS has much to be proud of
افتراضي Key Reversal Strategy

_External Inputs and Default Values_: These are parameters you will be able to change at any time prior to activating the strategy through the inputs...

External Inputs and Default Values: These are parameters you will be able to change at any time prior to activating the Strategy through the inputs window.

Length = 1 [This input is used to determine how many bars will be included in the array in the buy/sell logic]

Limit = 0
Stop = 0
Use SSL = False
Port = 25
Trailing Stop = 0
Email Alert = False

Order Notation

KeyRevLE = Buy Market Order
KeyRevLE_SL= Stop loss order for a long position
KeyRevLE_TP= Limit order for a long position
KeyRevSE = Sell Market Order
KeyRevSE_SL= Stop loss order for a short position
KeyRevSE_TP= Limit order for a short position

Buying logic

Suppose the “length” input is X (which by default is 1). The Strategy will compare the LOW of the current bar to the lowest LOW value of the previous X bars (lets call this “lowestlow”).

If the current low is less than “lowestlow,” and the close of the current bar is greater than the close of the previous bar, the Strategy will generate a market order to BUY at open price of the next bar.

Selling Logic

Suppose the “length” input is X (which by default is 1).). The Strategy will compare the HIGH of the current bar to the highest HIGH value of the previous X bars (lets call this “highesthigh”).

If the current high is greater than “highesthigh,” and the close of the current bar is less than the close of the previous bar, the Strategy will generate a market order to SELL at the open price of the next bar.



Exit Logic Long

The Strategy will automatically place a stop loss and/or take profit however many pips away from the open price as specified by the trader in the Strategy inputs.

Trailing Stop
If a trailing stop is added by the trader, the stop value will be changed dynamically for every bullish market movement.

Exit Logic Short

The Strategy will automatically place a stop loss and/or take profit however many pips away from the open price as specified by the trader in the Strategy inputs.

Trailing Stop
If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

Code:
using System;
namespace Broker.StrategyLanguage.Strategy
{
public class KeyReversal : BaseStrategyAdvisor
{
private int m_length = 1;
private double m_TP0;
private double m_SL0;
private double m_TP1;
private double m_SL1;
private IMarketOrder m_Order0;
private IPriceOrder m_Order0_TP;
private IPriceOrder m_Order0_SL;
private IMarketOrder m_Order1;
private IPriceOrder m_Order1_TP;
private IPriceOrder m_Order1_SL;
private bool Email_lock = true;
public KeyReversal(object ctx) :
base(ctx) {}
[Input]
public int length{
get { return m_length; }
set { m_length = value; }
}

private int m_Limit = 0;
[Input]
public int Limit
{
get{return m_Limit;}
set{m_Limit=value;}
}

private int m_Stop = 0;
[Input]
public int Stop
{
get{return m_Stop;}
set{m_Stop=value;}
}

private string m_Username = "";
[Input]
public string Username
{
get{return m_Username;}
set{m_Username=value;}
}

private string m_Password = "";
[Input]
public string Password
{
get{return m_Password;}
set{m_Password=value;}
}

private string m_Smtp = "";
[Input]
public string Smtp
{
get{return m_Smtp;}
set{m_Smtp=value;}
}

private string m_From = "";
[Input]
public string From
{
get{return m_From;}
set{m_From=value;}
}

private string m_To = "";
[Input]
public string To
{
get{return m_To;}
set{m_To=value;}
}

private bool m_UseSSL = false;
[Input]
public bool UseSSL
{
get{return m_UseSSL;}
set{m_UseSSL=value;}
}

private int m_Port = 25;
[Input]
public int Port
{
get{return m_Port;}
set{m_Port=value;}
}

private int m_TrailingStop = 0;
[Input]
public int TrailingStop
{
get{return m_TrailingStop;}
set{m_TrailingStop=value;}
}

private bool m_EmailAlert = false;
[Input]
public bool EmailAlert
{
get{return m_EmailAlert;}
set{m_EmailAlert=value;}
}

protected override void Construct() {
m_Order0 =
OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "KeyRevLE", OrderAction.Buy));
m_Order0_SL =
OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "KeyRevLE_SL", OrderAction.Sell));
m_Order0_TP =
OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "KeyRevLE_TP", OrderAction.Sell));
m_Order1 =
OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "KeyRevSE", OrderAction.SellShort));
m_Order1_SL =
OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "KeyRevSE_SL", OrderAction.BuyToCover));
m_Order1_TP =
OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "KeyRevSE_TP", OrderAction.BuyToCover));
الموضوع الأصلى من هنا: منتديات القرصان http://www.alkrsan.net/forum/caoun-ae-caounca-poetry-and-poets/31156-key-reversal-strategy.html
}
protected override void Initialize() {
}
protected override void Destroy() {}
protected override void Execute() {
if(Bars.Status == BarStatus.Close)
Email_lock = true;

CheckTrailingStop();
CheckExitLogic();

if ((Functions.DoubleLess(Bars.Low[0], Functions.Lowest(Bars.Low, length, 1)) &&
Functions.DoubleGreater(Bars.Close[0], Bars.Close[1]))){
if(Limit > 0) m_TP0 = Bars.Close[0] + Limit * Point; else m_TP0 = 0;
if(Stop > 0) m_SL0 = Bars.Close[0] - Stop * Point; else m_SL0 = 0;
if(m_EmailAlert == true && Email_lock == true) {
SendMail("Order0", "Order0 is traded at Price " + Bars.Close[0]);
Email_lock = false;
}
m_Order0.Generate();
}
if ((Functions.DoubleGreater(Bars.High[0], Functions.Highest(Bars.High, length, 1)) &&
Functions.DoubleLess(Bars.Close[0], Bars.Close[1]))){
if(Limit > 0) m_TP1 = Bars.Close[0] - Limit * Point; else m_TP1 = 0;
if(Stop > 0) m_SL1 = Bars.Close[0] + Stop * Point; else m_SL1 = 0;
if(m_EmailAlert == true && Email_lock == true) {
SendMail("Order1", "Order1 is traded at Price " + Bars.Close[0]);
Email_lock = false;
}
m_Order1.Generate();
}
}

private void CheckExitLogic() {
if(StrategyInfo.MarketPosition == 0) return;
if(StrategyInfo.MarketPosition > 0) {
if(m_TP0 > 0)
m_Order0_TP.Generate(m_TP0);
if(m_SL0 > 0)
m_Order0_SL.Generate(m_SL0);
}
if(StrategyInfo.MarketPosition < 0) {
if(m_TP1 > 0)
m_Order1_TP.Generate(m_TP1);
if(m_SL1 > 0)
m_Order1_SL.Generate(m_SL1);
}
}

private void CheckTrailingStop() {
if(m_TrailingStop == 0) return;
if(StrategyInfo.MarketPosition > 0) {
if(m_SL0 >0 && (Bars.Close[0] - m_SL0) > (Stop + m_TrailingStop) * Point)
m_SL0 = Bars.Close[0] - Stop * Point;
}
if(StrategyInfo.MarketPosition < 0) {
if(m_SL1 > 0 && (m_SL1 - Bars.Close[0]) > (Stop + m_TrailingStop) * Point)
m_SL1 = Bars.Close[0] + Stop * Point;
}
}

private double Point //Returns the point value
{
get{
if(Bars.Point < 0.01)
{
return(Bars.Point * 10);
}
else
{
return Bars.Point;
}
}
}

protected void SendMail(string subject, string msgToSend)
{
try
{
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(Smtp);
smtpClient.Credentials = new System.Net.NetworkCredential(Username, Password);
smtpClient.EnableSsl = UseSSL;
smtpClient.Port = Port;
// send our email
smtpClient.Send(From, To, subject, msgToSend);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}


Email Alerts

Not every Strategy has an email alert function embedded within its code. To verify if the Strategy you are using does, open the Format Strategy Advisor window for that stEA and see if it has the fields highlighted below.



The highlighted fields should be filled in as follows in order to activate the email alerts:

Username – the user name of the email you would like to use as the sender
Password – the password used to log on to your email account
Smtp – This will vary depending on your email provider (gmail’s SMTP is smtp.gmail.com and yahoo’s is plus.smtp.mail.yahoo.com)
From – the full email address from which the email alert will be sent
To- the full email address to which the email alert will be sent (it can be the same as the address in the 'from' field)
UseSSL – the use of SSL also depends on the email provider. Please verify whether or not your email provider uses SSL. If so, this field should be changed to “True.”
EmailAlert – this field should be changed to “True,” if you would like to activate email alerts

Attached Images
Attached Files KeyReversal.fxd (2.8 KB)


_External Inputs and Default Values_: These are...

Key Reversal Strategy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
رد مع اقتباس
إضافة رد

العلامات المرجعية


يتصفح الموضوع حالياً : 1 (0 عضو و 1 ضيف)
 
أدوات الموضوع
انواع عرض الموضوع

ضوابط المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا يمكنك اضافة مرفقات
لا يمكنك تعديل مشاركاتك

BB code متاحة
كود [IMG] متاحة
كود HTML معطلة
Trackbacks are معطلة
Pingbacks are معطلة
Refbacks are معطلة



جميع الأوقات بتوقيت GMT +3. الساعة الآن 09:16 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.1 PL1

تعريب » القرصان - خدمات الويب

جميع الحقوق محفوظة alkrsan 2006-2014


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474