Repository navigation
Expand file tree
/
Copy pathDanScalpMaster.cpp
More file actions
755 lines (561 loc) · 25.9 KB
/
Copy pathDanScalpMaster.cpp
File metadata and controls
755 lines (561 loc) · 25.9 KB
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
#include "sierrachart.h"
#include "common.h"
const int ALGO_MODE_NORMAL = 0;
const int ALGO_MODE_ELITE = 1;
void scalperDisplayBotBadge(SCStudyInterfaceRef sc, bool enabled) {
s_UseTool sessionStatusText;
sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, 4717);
sessionStatusText.Clear();
sessionStatusText.ChartNumber = sc.ChartNumber;
sessionStatusText.Region = sc.GraphRegion;
sessionStatusText.DrawingType = DRAWING_TEXT;
sessionStatusText.TextAlignment = DT_RIGHT;
sessionStatusText.FontSize = 10;
sessionStatusText.UseRelativeVerticalValues = 1;
sessionStatusText.ReverseTextColor = 0;
sessionStatusText.LineNumber = 4717;
sessionStatusText.AddMethod = UTAM_ADD_OR_ADJUST;
// vertical position .... 100 = top
sessionStatusText.BeginValue = 96;
// horizontal position ... 0-150
sessionStatusText.BeginDateTime = 148;
sessionStatusText.Text.Format("ScalpMaster7000: %s", enabled? "ENABLED" : "DISABLED");
sessionStatusText.Color = enabled ? RGB(0, 255, 0) : RGB(255, 0, 0);
sessionStatusText.FontBold = true;
sc.UseTool(sessionStatusText);
}
int scalperPlaceMarketOrder(SCStudyInterfaceRef sc, int orderType, double quantity, double targetPrice, double stopPrice, int beTriggerOffset) {
// bail out if quantity <= 0
if (quantity <= 0) {
sc.AddMessageToLog("======= ABORTING Market order - Reason: Quantity <= 0!", 0);
return -1;
}
// bail out if we already have an open order running
if (areWeInPosition(sc, orderType)) {
sc.AddMessageToLog("======= ABORTING Market order - Reason: We are already in position!", 0);
return -1;
}
s_SCNewOrder NewOrder;
SCString MessageText;
sc.AddMessageToLog("======= Preparing Market order.", 0);
//debugPrintCurrentCandle(sc, orderType);
MessageText.Format("== Setting order quantity to %u", static_cast<int>(quantity));
sc.AddMessageToLog(MessageText, 0);
NewOrder.OrderQuantity = quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_DAY;
//Target
if (targetPrice != NULL) {
MessageText.Format("== Attaching OCO Target Limit order to price %.02f", targetPrice);
sc.AddMessageToLog(MessageText, 0);
NewOrder.Target1Price = targetPrice;
NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
}
//Stop
// Attach trailing stop IF we want that and IF we are in konter and IF the current target price is FARTHER AWAY than the trailing offset
if (stopPrice != NULL) {
MessageText.Format("== Attaching normal OCO Stop order to price %.02f", stopPrice);
sc.AddMessageToLog(MessageText, 0);
NewOrder.StopAllPrice = stopPrice;
NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_STOP;
// NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_TRIGGERED_TRAILING_STOP_3_OFFSETS;
//
// NewOrder.TriggeredTrailStopTrailPriceOffset = sc.TickSize * 12;
// NewOrder.TriggeredTrailStopTriggerPriceOffset = sc.TickSize * 5;
// NewOrder.Stop1Price = stopPrice;
}
NewOrder.MoveToBreakEven.Type = MOVETO_BE_ACTION_TYPE_OFFSET_TRIGGERED;
NewOrder.MoveToBreakEven.BreakEvenLevelOffsetInTicks = 1;
NewOrder.MoveToBreakEven.TriggerOffsetInTicks = beTriggerOffset;
int Result;
if (orderType == ORDER_TYPE_BUY) {
sc.AddMessageToLog("======= Sending out Market Buy order.", 0);
Result = static_cast<int>(sc.BuyOrder(NewOrder));
}
else {
sc.AddMessageToLog("======= Sending out Market Sell order.", 0);
Result = static_cast<int>(sc.SellOrder(NewOrder));
}
return Result;
}
int scalperFromPanelPlaceMarketOrder(SCStudyInterfaceRef sc, int orderType, double quantity) {
// bail out if quantity <= 0
if (quantity <= 0) {
sc.AddMessageToLog("======= ABORTING Market order - Reason: Quantity <= 0!", 0);
return -1;
}
// bail out if we already have an open order running
if (areWeInPosition(sc, orderType)) {
sc.AddMessageToLog("======= ABORTING Market order - Reason: We are already in position!", 0);
return -1;
}
s_SCNewOrder NewOrder;
SCString MessageText;
sc.AddMessageToLog("======= Preparing Market order.", 0);
//debugPrintCurrentCandle(sc, orderType);
MessageText.Format("== Setting order quantity to %u", static_cast<int>(quantity));
sc.AddMessageToLog(MessageText, 0);
NewOrder.OrderQuantity = quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_DAY;
int Result;
if (orderType == ORDER_TYPE_BUY) {
sc.AddMessageToLog("======= Sending out Market Buy order.", 0);
Result = static_cast<int>(sc.BuyOrder(NewOrder));
}
else {
sc.AddMessageToLog("======= Sending out Market Sell order.", 0);
Result = static_cast<int>(sc.SellOrder(NewOrder));
}
return Result;
}
int scalperPlaceLimitOrder(SCStudyInterfaceRef sc, int orderType, double quantity, double limitPrice, double targetPrice, double stopPrice, int beTriggerOffset) {
// bail out if quantity <= 0
if (quantity <= 0) {
sc.AddMessageToLog("======= ABORTING Limit order - Reason: Quantity <= 0!", 0);
return -1;
}
// bail out if we already have an open order running
if (areWeInPosition(sc, orderType)) {
sc.AddMessageToLog("======= ABORTING Limit order - Reason: We are already in position!", 0);
return -1;
}
s_SCNewOrder NewOrder;
SCString MessageText;
sc.AddMessageToLog("======= Preparing Limit order.", 0);
//debugPrintCurrentCandle(sc, orderType);
MessageText.Format("== Setting order quantity to %u", static_cast<int>(quantity));
sc.AddMessageToLog(MessageText, 0);
NewOrder.OrderQuantity = quantity;
NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
NewOrder.Price1 = limitPrice;
NewOrder.TimeInForce = SCT_TIF_DAY;
//Target
if (targetPrice != NULL) {
MessageText.Format("== Attaching OCO Target Limit order to price %.02f", targetPrice);
sc.AddMessageToLog(MessageText, 0);
NewOrder.Target1Price = targetPrice;
NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
}
//Stop
// Attach trailing stop IF we want that and IF we are in konter and IF the current target price is FARTHER AWAY than the trailing offset
if (stopPrice != NULL) {
MessageText.Format("== Attaching normal OCO Stop order to price %.02f", stopPrice);
sc.AddMessageToLog(MessageText, 0);
NewOrder.StopAllPrice = stopPrice;
NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_STOP;
// NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_TRIGGERED_TRAILING_STOP_3_OFFSETS;
//
// NewOrder.TriggeredTrailStopTrailPriceOffset = sc.TickSize * 12;
// NewOrder.TriggeredTrailStopTriggerPriceOffset = sc.TickSize * 5;
// NewOrder.Stop1Price = stopPrice;
}
NewOrder.MoveToBreakEven.Type = MOVETO_BE_ACTION_TYPE_OFFSET_TRIGGERED;
NewOrder.MoveToBreakEven.BreakEvenLevelOffsetInTicks = 1;
NewOrder.MoveToBreakEven.TriggerOffsetInTicks = beTriggerOffset;
int Result;
if (orderType == ORDER_TYPE_BUY) {
sc.AddMessageToLog("======= Sending out Market Buy order.", 0);
Result = static_cast<int>(sc.BuyOrder(NewOrder));
}
else {
sc.AddMessageToLog("======= Sending out Market Sell order.", 0);
Result = static_cast<int>(sc.SellOrder(NewOrder));
}
return Result;
}
float getPOCPriceForBar(SCStudyGraphRef sc, int barIndex) {
s_VolumeAtPriceV2 VolumeAtPrice;
sc.GetPointOfControlPriceVolumeForBar(barIndex, VolumeAtPrice);
if (VolumeAtPrice.PriceInTicks != 0)
{
return static_cast<float>(sc.TicksToPriceValue(VolumeAtPrice.PriceInTicks));
}
else { return -1; }
}
int getDeltaForPriceRange(SCStudyGraphRef sc, unsigned int barIndex, float startPrice, float endPrice) {
s_VolumeAtPriceV2 t_VolumeAtPrice;
int startPriceInTicks = sc.PriceValueToTicks(startPrice);
int endPriceInTicks = sc.PriceValueToTicks(endPrice);
int delta = 0;
// swap prices if necessary
if (endPriceInTicks < startPriceInTicks) {
int keks = endPriceInTicks;
endPriceInTicks = startPriceInTicks;
startPriceInTicks = keks;
}
for (int currentTick = startPriceInTicks; currentTick <= endPriceInTicks; currentTick++) {
t_VolumeAtPrice = sc.VolumeAtPriceForBars->GetVAPElementAtPrice(barIndex, currentTick);
delta += (t_VolumeAtPrice.AskVolume - t_VolumeAtPrice.BidVolume);
}
//Calculate the price. This requires multiplying p_VolumeAtPrice->PriceInTicks by the tick size
// float Price = p_VolumeAtPrice->PriceInTicks * sc.TickSize;
//Other members available:
//unsigned int AskVolume = p_VolumeAtPrice->AskVolume;
// unsigned int BidVolume = p_VolumeAtPrice->BidVolume;
// unsigned int NumberOfTrades = p_VolumeAtPrice->NumberOfTrades;
return delta;
}
void scalperProcessOneBarFlo(SCStudyGraphRef sc, int index, bool drawAddedZone = false) {
}
void scalperProcessOneBarDan(SCStudyGraphRef sc, int index, bool drawAddedZone = false) {
SCInputRef Input_Enabled = sc.Input[0];
SCInputRef Input_MinWickLength = sc.Input[1];
SCInputRef Input_FlipOrders = sc.Input[2];
SCInputRef Input_TradeTypesToTake = sc.Input[3];
SCInputRef Input_IndicatorOnly = sc.Input[4];
SCInputRef Input_MinBarDelta = sc.Input[6];
SCInputRef Input_BETriggerOffset = sc.Input[7];
SCInputRef Input_POCNeedsToBeInWick = sc.Input[8];
SCInputRef Input_TradeDirectionAccordingToBracketMasterMarketDirection = sc.Input[9];
SCInputRef Input_ChartAndStudyWithBracketMaster = sc.Input[10];
if (!(sc.GetBarHasClosedStatus(index) == BHCS_BAR_HAS_CLOSED))
{
return;
}
Bar currentBar = getBar(sc, index);
if (currentBar.open == currentBar.close) {
// doji, ignore
return;
}
if (!currentBar.hasBottomWick(sc) && !currentBar.hasTopWick(sc)) {
// no wicks, return
return;
}
int BeginIndex = 0, EndIndex = 0;
SCString DebugString;
if (static_cast<int>(sc.VolumeAtPriceForBars->GetNumberOfBars()) < sc.ArraySize)
return;
int topWickLength = currentBar.wickLengthTopInTicks(sc);
int bottomWickLength = currentBar.wickLengthBottomInTicks(sc);
// green: lunte unten, sonst
bool green = (currentBar.hasBottomWick(sc) && bottomWickLength > topWickLength);
bool red = (currentBar.hasTopWick(sc) && topWickLength > bottomWickLength);
int delta = static_cast<int>(sc.BaseDataIn[SC_ASKVOL][sc.Index] - sc.BaseDataIn[SC_BIDVOL][sc.Index]);
if (abs(delta) < Input_MinBarDelta.IntValue)
return;
int currentMarketDirection = sc.GetPersistentIntFromChartStudy(Input_ChartAndStudyWithBracketMaster.GetChartNumber(), Input_ChartAndStudyWithBracketMaster.GetStudyID(), PERSISTENT_MARKET_DIRECTION);
if (green) {
float bodyOpen = currentBar.open;
float bodyClose = currentBar.close;
float wickStart;
float wickEnd;
// only process green bars with wick on the bottom;
if (!currentBar.hasBottomWick(sc)) return;
// only process green bars with longer wick on the bottom;
if (topWickLength >= bottomWickLength) return;
// only process bars with the min. wick length
if (bottomWickLength < Input_MinWickLength.GetInt()) return;
// wick on bottom
wickStart = currentBar.low;
wickEnd = currentBar.green() ? currentBar.open - (1 * sc.TickSize) : currentBar.close - (1 * sc.TickSize);
if (Input_POCNeedsToBeInWick.BooleanValue) {
if (getPOCPriceForBar(sc, index) >= (currentBar.green() ? currentBar.open : currentBar.close)) return;
}
int bodyDelta = getDeltaForPriceRange(sc, index, bodyOpen, bodyClose);
int wickDelta = getDeltaForPriceRange(sc, index, wickStart, wickEnd);
if (bodyDelta > 0 && wickDelta < 0) {
sc.Subgraph[0].Data[index] = currentBar.open;
if (areWeInPosition(sc, ORDER_TYPE_SELL) && currentBar.green()) {
// counter signal, close position
sc.CancelAllOrders();
sc.FlattenPosition();
}
if (Input_TradeDirectionAccordingToBracketMasterMarketDirection.BooleanValue) {
if (currentMarketDirection != ORDER_TYPE_BUY) return;
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceMarketOrder(sc, ORDER_TYPE_BUY, 3, bodyClose + (21 * sc.TickSize), currentBar.low - 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
if (!Input_IndicatorOnly.BooleanValue) scalperPlaceLimitOrder(sc, ORDER_TYPE_BUY, 3, (getPOCPriceForBar(sc, index) + 3 * sc.TickSize), bodyClose + (21 * sc.TickSize), currentBar.low - 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
}
else {
if (Input_TradeTypesToTake.GetIndex() != DESIRED_TRADE_TYPES_SHORT_ONLY) {
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceMarketOrder(sc, ORDER_TYPE_BUY, 3, bodyClose + (21 * sc.TickSize), currentBar.low - 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
if (!Input_IndicatorOnly.BooleanValue) scalperPlaceLimitOrder(sc, ORDER_TYPE_BUY, 3, (getPOCPriceForBar(sc, index) + 3 * sc.TickSize), bodyClose + (21 * sc.TickSize), currentBar.low - 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
}
}
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceOrder(sc, ORDER_TYPE_BUY, 3, bodyClose + (80 * sc.TickSize), (getPOCPriceForBar(sc, index) - 3 * sc.TickSize));
}
// do the bull dance
}
else if (red) {
float bodyOpen = currentBar.open;
float bodyClose = currentBar.close;
float wickStart;
float wickEnd;
// only process red bars with wick on the bottom;
if (!currentBar.hasTopWick(sc)) return;
// only process red bars with longer wick on the top;
if (bottomWickLength >= topWickLength) return;
// only process bars with the min. wick length
if (topWickLength < Input_MinWickLength.GetInt()) return;
// wick on top
wickStart = currentBar.high;
wickEnd = currentBar.green() ? currentBar.close + (1 * sc.TickSize) : currentBar.open + (1 * sc.TickSize);
if (Input_POCNeedsToBeInWick.BooleanValue) {
if (getPOCPriceForBar(sc, index) <= (currentBar.green() ? currentBar.close : currentBar.open)) return;
}
int bodyDelta = getDeltaForPriceRange(sc, index, bodyOpen, bodyClose);
int wickDelta = getDeltaForPriceRange(sc, index, wickStart, wickEnd);
if (bodyDelta < 0 && wickDelta > 0) {
sc.Subgraph[1].Data[index] = currentBar.open;
if (areWeInPosition(sc, ORDER_TYPE_BUY) && currentBar.red()) {
// counter signal, close position
sc.CancelAllOrders();
sc.FlattenPosition();
}
if (Input_TradeDirectionAccordingToBracketMasterMarketDirection.BooleanValue) {
if (currentMarketDirection != ORDER_TYPE_SELL) return;
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceMarketOrder(sc, ORDER_TYPE_SELL, 3, bodyClose - (21 * sc.TickSize), currentBar.high + 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
if (!Input_IndicatorOnly.BooleanValue) scalperPlaceLimitOrder(sc, ORDER_TYPE_SELL, 3, (getPOCPriceForBar(sc, index) - 3 * sc.TickSize), bodyClose - (21 * sc.TickSize), currentBar.high + 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
}
else {
if (Input_TradeTypesToTake.GetIndex() != DESIRED_TRADE_TYPES_LONG_ONLY) {
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceOrder(sc, ORDER_TYPE_SELL, 3, bodyClose - (80 * sc.TickSize), (getPOCPriceForBar(sc, index) + 3 * sc.TickSize));
// if (!Input_IndicatorOnly.BooleanValue) scalperPlaceMarketOrder(sc, ORDER_TYPE_SELL, 3, bodyClose - (21 * sc.TickSize), currentBar.high + 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
if (!Input_IndicatorOnly.BooleanValue) scalperPlaceLimitOrder(sc, ORDER_TYPE_SELL, 3, (getPOCPriceForBar(sc, index) - 3 * sc.TickSize), bodyClose - (21 * sc.TickSize), currentBar.high + 3 * sc.TickSize, Input_BETriggerOffset.IntValue);
}
}
}
// do the bear dance
}
}
void scalperProcessIntraBarCalculations(SCStudyInterfaceRef sc) {
Bar currentBar = getBar(sc, sc.Index);
if (static_cast<int>(sc.VolumeAtPriceForBars->GetNumberOfBars()) < sc.ArraySize)
return;
unsigned int TotalVolume = 0;
const s_VolumeAtPriceV2* p_VolumeAtPrice = NULL;
int VAPSizeAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);
for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; VAPIndex++)
{
if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice))
break;
TotalVolume += p_VolumeAtPrice->Volume;
}
}
void scalperProcessBarCalculations(SCStudyInterfaceRef sc, bool barClose = false, int index = 0, bool doTrades = false) {
SCInputRef Input_Enabled = sc.Input[0];
SCInputRef Input_MinWickLength = sc.Input[1];
SCInputRef Input_FlipOrders = sc.Input[2];
SCInputRef Input_TradeTypesToTake = sc.Input[3];
SCInputRef Input_IndicatorOnly = sc.Input[4];
SCInputRef Input_MinBarDelta = sc.Input[6];
SCInputRef Input_BETriggerOffset = sc.Input[7];
SCInputRef Input_POCNeedsToBeInWick = sc.Input[8];
SCInputRef Input_TradeDirectionAccordingToBracketMasterMarketDirection = sc.Input[9];
SCInputRef Input_ChartAndStudyWithBracketMaster = sc.Input[10];
if (barClose && !(sc.GetBarHasClosedStatus(index) == BHCS_BAR_HAS_CLOSED))
{
return;
}
if (!barClose) return;
Bar currentBar = getBar(sc, index);
if (currentBar.open == currentBar.close) {
// doji, ignore
return;
}
float topRangeStart = currentBar.high;
float topRangeEnd = topRangeStart - 3 * sc.TickSize;
float bottomRangeStart = topRangeEnd - 1 * sc.TickSize;
float bottomRangeEnd = bottomRangeStart - 3 * sc.TickSize;
int topRangeDelta = getDeltaForPriceRange(sc, index, topRangeStart, topRangeEnd);
int bottomRangeDelta = getDeltaForPriceRange(sc, index, bottomRangeStart, bottomRangeEnd);
sc.Subgraph[2].Data[index] = static_cast<float>(topRangeDelta);
sc.Subgraph[3].Data[index] = static_cast<float>(bottomRangeDelta);
if (currentBar.green()) {
// green candle
if (topRangeDelta > 0 && bottomRangeDelta < -200) {
// lang gehen
sc.Subgraph[0].Data[index] = currentBar.low;
if (areWeInPosition(sc, ORDER_TYPE_SELL)) {
// counter signal, close position
sc.CancelAllOrders();
sc.FlattenPosition();
}
if (Input_TradeTypesToTake.GetIndex() != DESIRED_TRADE_TYPES_SHORT_ONLY) {
if ((!Input_IndicatorOnly.BooleanValue) && doTrades) scalperFromPanelPlaceMarketOrder(sc, ORDER_TYPE_BUY, 3);
}
}
}
else {
// red candle
if (topRangeDelta > 200 && bottomRangeDelta < 0) {
// kurz gehen
sc.Subgraph[1].Data[index] = currentBar.high;
if (areWeInPosition(sc, ORDER_TYPE_BUY)) {
// counter signal, close position
sc.CancelAllOrders();
sc.FlattenPosition();
}
if (Input_TradeTypesToTake.GetIndex() != DESIRED_TRADE_TYPES_LONG_ONLY) {
if ((!Input_IndicatorOnly.BooleanValue) && doTrades) scalperFromPanelPlaceMarketOrder(sc, ORDER_TYPE_SELL, 3);
}
}
}
}
/*==========================================================================*/
SCSFExport scsf_ScalpMaster(SCStudyInterfaceRef sc)
{
SCInputRef Input_Enabled = sc.Input[0];
// SCInputRef Input_MinWickLength = sc.Input[1];
// SCInputRef Input_FlipOrders = sc.Input[2];
SCInputRef Input_TradeTypesToTake = sc.Input[3];
SCInputRef Input_IndicatorOnly = sc.Input[4];
// SCInputRef Input_HowManyBarsBack = sc.Input[5];
// SCInputRef Input_MinBarDelta = sc.Input[6];
// SCInputRef Input_BETriggerOffset = sc.Input[7];
// SCInputRef Input_POCNeedsToBeInWick = sc.Input[8];
SCInputRef Input_TradeDirectionAccordingToBracketMasterMarketDirection = sc.Input[9];
SCInputRef Input_ChartAndStudyWithBracketMaster = sc.Input[10];
SCInputRef Input_TimedActivationDeactivation = sc.Input[11];
SCInputRef Input_TimedActivationDeactivationSessionStart = sc.Input[12];
SCInputRef Input_TimedActivationDeactivationSessionEnd = sc.Input[13];
// automatic enable/disable of wiz
SCString MessageText;
if (sc.SetDefaults)
{
sc.GraphName = "ScalpMaster7000";
sc.AutoLoop = 1;//Auto looping
sc.GraphRegion = 0;
sc.ScaleRangeType = SCALE_SAMEASREGION;
Input_Enabled.Name = "ScalpMaster Enabled";
Input_Enabled.SetYesNo(true);
// Input_MinWickLength.Name = "Min. Wick Length";
// Input_MinWickLength.SetInt(1);
// Input_MinWickLength.SetIntLimits(1, 100);
// Input_FlipOrders.Name = "Flip Orders";
// Input_FlipOrders.SetYesNo(true);
Input_TradeTypesToTake.Name = "What Trades to Take";
Input_TradeTypesToTake.SetCustomInputStrings("LONG and SHORT;LONG Only;SHORT Only");
Input_TradeTypesToTake.SetCustomInputIndex(0);
Input_IndicatorOnly.Name = "No Trades, just Display entries taken in the past";
Input_IndicatorOnly.SetYesNo(false);
// Input_HowManyBarsBack.Name = "Look How Many Bars Back (overrules Days Back)";
// Input_HowManyBarsBack.SetInt(100);
// Input_HowManyBarsBack.SetIntLimits(1, 1000);
// Input_MinBarDelta.Name = "Min. Delta of the Bar to be relevant";
// Input_MinBarDelta.SetInt(10);
// Input_MinBarDelta.SetIntLimits(1, 1000);
// Input_BETriggerOffset.Name = "Trigger Offset for Break Even";
// Input_BETriggerOffset.SetInt(10);
// Input_BETriggerOffset.SetIntLimits(1, 1000);
// Input_POCNeedsToBeInWick.Name = "Bar POC Needs To Be Inside John Wick";
// Input_POCNeedsToBeInWick.SetYesNo(true);
Input_TradeDirectionAccordingToBracketMasterMarketDirection.Name = "Only Take Trades in M15 Market Direction.";
Input_TradeDirectionAccordingToBracketMasterMarketDirection.SetYesNo(true);
Input_ChartAndStudyWithBracketMaster.Name = "Chart and Study ID for the BracketMaster (like in M15 Chart)";
Input_ChartAndStudyWithBracketMaster.SetChartStudyValues(1, 1);
Input_TimedActivationDeactivation.Name = "Automatically Activate/Deactivate Wiz for Sessions";
Input_TimedActivationDeactivation.SetYesNo(true);
Input_TimedActivationDeactivationSessionStart.Name = "Session Start Time";
Input_TimedActivationDeactivationSessionStart.SetTime(HMS_TIME(9, 00, 0));
Input_TimedActivationDeactivationSessionEnd.Name = "Session End Time";
Input_TimedActivationDeactivationSessionEnd.SetTime(HMS_TIME(19, 00, 0));
sc.Subgraph[0].Name = "Long Entries";
sc.Subgraph[0].DrawStyle = DRAWSTYLE_ARROW_UP; // Look in scconstants.h for other draw styles
sc.Subgraph[0].LineStyle = LINESTYLE_DASH;
sc.Subgraph[0].LineWidth = 3;
sc.Subgraph[0].AutoColoring = AUTOCOLOR_NONE;
sc.Subgraph[0].PrimaryColor = RGB(0, 255, 0); // Green
sc.Subgraph[1].Name = "Short Entries";
sc.Subgraph[1].DrawStyle = DRAWSTYLE_ARROW_DOWN; // Look in scconstants.h for other draw styles
sc.Subgraph[1].LineStyle = LINESTYLE_DASH;
sc.Subgraph[1].LineWidth = 3;
sc.Subgraph[1].AutoColoring = AUTOCOLOR_NONE;
sc.Subgraph[1].PrimaryColor = RGB(255, 0, 0); // Red
sc.Subgraph[2].Name = "TopRangeDelta";
sc.Subgraph[2].DrawStyle = DRAWSTYLE_HIDDEN; // Look in scconstants.h for other draw styles
sc.Subgraph[3].Name = "BottomRangeDelta";
sc.Subgraph[3].DrawStyle = DRAWSTYLE_HIDDEN; // Look in scconstants.h for other draw styles
sc.ReceivePointerEvents = false;
// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
sc.FreeDLL = 1;
sc.AllowMultipleEntriesInSameDirection = 1;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = 1;
sc.CancelAllOrdersOnEntriesAndReversals = 0;
sc.AllowOnlyOneTradePerBar = 0;
sc.SupportReversals = 0;
sc.AllowEntryWithWorkingOrders = 1;
sc.SupportAttachedOrdersForTrading = 0;
sc.UseGUIAttachedOrderSetting = 1;
sc.MaintainVolumeAtPriceData = 1;
//use a high-value to effectively not put any Position Quantity restrictions
sc.MaximumPositionAllowed = 100000000;
return;
}
if (sc.IsUserAllowedForSCDLLName == false)
{
if (sc.Index == 0)
{
sc.AddMessageToLog("You are not allowed to use this study", 1);
}
return;
}
if (Input_TradeDirectionAccordingToBracketMasterMarketDirection.BooleanValue) {
SCString BracketMasterStudyName;
sc.GetStudyInternalIdentifier(Input_ChartAndStudyWithBracketMaster.GetChartNumber(), Input_ChartAndStudyWithBracketMaster.GetStudyID(), BracketMasterStudyName);
if (!(BracketMasterStudyName.Compare("BracketMaster", 13) == 0)) {
sc.AddMessageToLog("Cantt find configured BracketMaster study. Exiting.", 1);
// sorry, wrong chart/study for bracket master ... exit
return;
}
}
if (sc.LastCallToFunction)
{
// abriss
return;
}
if (sc.HideStudy) return;
//For safety must never do any order management while historical data is being downloaded.
if (sc.ChartIsDownloadingHistoricalData(sc.ChartNumber))
return;
sc.SendOrdersToTradeService = !sc.GlobalTradeSimulationIsOn;
int index = sc.Index;
if (sc.UpdateStartIndex == 0)//Perform initialization
{
// sc.SetPersistentInt(PERSISTENT_REFERENCE_BAR_INDEX, -1);
// sc.SetPersistentInt(PERSISTENT_MARKET_DIRECTION, -1);
// sc.SetPersistentInt(PERSISTENT_CURRENT_ZONE_LINE_NUMBER, -1);
for (int i = sc.Index; i < sc.ArraySize; i++) {
scalperProcessBarCalculations(sc, true, i, false);
}
// initialDetectionOfAllBrackets(sc, Input_HowManyDaysBack.GetInt(), Input_LimitToBarsInsteadOfDays.GetBoolean(), Input_HowManyBarsBack.GetInt());
// return;
}
// main update, done after the next bar is finished
// if (index == 0) {
// return;
// }
// if (!Input_Enabled.BooleanValue) return;
if (!(sc.GetBarHasClosedStatus(index) == BHCS_BAR_HAS_CLOSED))
{
// scalperProcessBarCalculations(sc, false);
return;
}
if (Input_TimedActivationDeactivation.GetBoolean()) {
int sessionstartTime = Input_TimedActivationDeactivationSessionStart.GetTime();
int sessionendTime = Input_TimedActivationDeactivationSessionEnd.GetTime();
SCDateTime CurrentDateTime;
if (sc.IsReplayRunning())
// CurrentDateTime = sc.CurrentDateTimeForReplay;
CurrentDateTime = sc.GetEndingDateTimeForBarIndex(sc.Index);
else
CurrentDateTime = sc.CurrentSystemDateTime;
int currentTime = CurrentDateTime.GetTime();
if (
(currentTime < sessionstartTime) ||
(currentTime > sessionendTime)
) {
Input_Enabled.SetYesNo(false);
scalperDisplayBotBadge(sc, false);
}
else {
Input_Enabled.SetYesNo(true);
scalperDisplayBotBadge(sc, true);
}
}
if (!Input_Enabled.BooleanValue) return;
// process bar close eval
scalperProcessBarCalculations(sc, true, sc.Index, true);
// scalperProcessOneBar(sc, sc.Index, true);
// displayBotBadge(sc, sc.GetPersistentInt(PERSISTENT_MARKET_DIRECTION));
}