algorithmic-trading

Risk Management: If already long then do not place new order

风格不统一 提交于 2020-01-05 08:23:18
问题 If the flag is already indicating long, there should not be a new flag indicating long. If flag does not indicate long evaluate the expression longCondition = if (strategy.long) ? false: (rsi<30) and (close>moving_avg) shortCondition = if (strategy.short) ? false: (rsi>70) and (close<moving_avg) Processing script... line 30: mismatched input 'shortCondition' expecting 'end of line without line continuation' 回答1: I assume this is an indicator and not a strategy. Because you can configure how

LCS ALGORITHM ( example )

…衆ロ難τιáo~ 提交于 2020-01-03 02:32:07
问题 There's a dynamic programming algorithm to find the Longest Common Subsequence of two sequences. How can I find the LCS algorithm of two sequences X and Y. (Test of correctness) (a) X = ABEDFEESTYH Y=ABEDFEESTYHABCDF (b) X = BFAAAABBBBBJPRSTY Y=ABCDEFGHIJKLMNOPRS (c) X = ϕ (Empty Sequence), Y = BABADCAB 回答1: Here is an online calculator http://igm.univ-mlv.fr/~lecroq/seqcomp/node4.html Java public class LCS { public static void main(String[] args) { String x = StdIn.readString(); String y =

Convert from R to quantstrat setup for trading strategy backtesting

丶灬走出姿态 提交于 2019-12-30 05:34:05
问题 I am trying to backtest a trading strategy with "quantstrat" package. My strategy is composed by 4 indicators, 3 different EMAs and 1 lagged EMA. I want to go long when: EMA1 > EMA2 & EMA1 > EMA3 & EMA1_lag < EMA1 I want to exit and go flat when: EMA1 < EMA3 It's pretty simple but I am not able to write it into quantstrat environment. Here's a data integrity check function used in both examples: # Data integrity check checkBlotterUpdate <- function(port.st,account.st,verbose=TRUE) { ok <-

MQL4: Read single value from CSV

梦想的初衷 提交于 2019-12-25 08:15:59
问题 I'm trying to fetch one value from the data source website Quandl to be used within a MetaTrader4 script. The data source site provides a method to export data via API formats including .csv , .json or .xml . I have chosen the .csv format, which the data source website then provides an API call for me to use in the following format: https://www.quandl.com/api/v3/datasets/ADB/LAB_UNEMP_JPN.csv?rows=1&api_key=my_api_key By using the rows=1 parameter in the above API call , I can choose to just

simple moving average of “live” stream - fast implementation

廉价感情. 提交于 2019-12-24 04:44:22
问题 In my trading application I have "live ticks" of stock prices. I need to maintain SMA. Let's assume I want SMA of 20 candles, where duration of each candle is 10 seconds. This means that Every 10 seconds I have "checkpoint" where: I "close" current candle and store average price for the last 10 seconds. Average is (max - min) / 2 I "start" new candle and store last price. I clean-up "outdated" candle. Every tick: I update "last" price of current "forming" candle and recalculate SMA. So on any

ValueError: Length of passed values is 7, index implies 0

我的梦境 提交于 2019-12-23 17:40:21
问题 I am trying to get 1minute open, high, low, close, volume values from bitmex using ccxt. everything seems to be fine however im not sure how to fix this error. I know that the index is 7 because there are 7 values in the OHLCcolumns that I am getting into the dataframe. I am not sure why it is instead implying there are 0. Thanks so much this has been giving me a headache all day :( # noinspection PyUnresolvedReferences from datetime import datetime # noinspection PyUnresolvedReferences

How to “tie” 3 RSI-indicators to one Bollinger Band, using IMAonArray()?

你离开我真会死。 提交于 2019-12-23 05:44:30
问题 There are 3 RSI indicators, each having its own period. I want to tie all 3 to one Bollinger Band. Tell me how to do this better? for(i=limit; i>=0; i--) { ma=iMAOnArray(RSI,0,bb_period,0,0,i); // midle stdev=iStdDevOnArray(RSI,0,bb_period,0,0,i); // dev BBUP[i]=ma+bb_dev*stdev; // up BBDOWN[i]=ma-bb_dev*stdev; // down Buff4[i]=0; Buff5[i]=0; } if(limit<Bars-1) limit++; for(i=limit; i>0; i--) { if(PrevSignal >= 0) { if( RSI[i] < BBDOWN[i] && RSI[i+1] < BBUP[i+1] && RSI2[i] < BBDOWN[i] && RSI2

Why is my EA not moving my position to breakeven?

三世轮回 提交于 2019-12-23 03:24:06
问题 I'm attempting to modify my market orders to breakeven the position when the position get 100 pips to the good. This also accounts for the StopLevels which are around 20-30 pips for my broker. It checks the param's via a " for(){...} loop" function The MagicNumber is the timeframe number for the chart it is on (i.e. 240 =4H, 60 =1H) I don't set a TakeProfit price & initially no StopLoss price. The EA is not adding a SL to be equal to the opening price when the trade reaches 100 pip in profit

How to call a function from a DLL file from [ MQL5 ] code?

Deadly 提交于 2019-12-23 02:38:07
问题 Why the first MessageBox() works and the second doesn't? I don't know where the problem is. Does the MQL5 can access the dll file? I need to to call C# functions that read JSON . No errors appear in MetaEditor . C# .dll file: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; namespace TestMe { class Test { // [DllExport("Add", CallingConvention = CallingConvention.StdCall)] public static

How to set order few pips above order initiation bar in MQL4

左心房为你撑大大i 提交于 2019-12-21 06:42:37
问题 I would like to create a stoploss order that will be placed above the high of the previous order's initiation bar in case this is a Sell order OR below the low of the previous order's initiation bar in case this is a Buy order. Here is a picture to illustrate the issue ( the example depicts a sell order case ): Any idea how to do that? The code below works fine if I use stoploss that is fixed. If I replace the stoploss with variables that are based on High or Low no orders are fired. Here is